public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Willgerodt, Felix" <felix.willgerodt@intel.com>
To: "Metzger, Markus T" <markus.t.metzger@intel.com>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH 08/10] btrace, python: Enable ptwrite listener registration.
Date: Mon, 14 Jun 2021 14:53:11 +0000	[thread overview]
Message-ID: <b1a208bd39e2497382ef591c79aa9c42@intel.com> (raw)
In-Reply-To: <A78C989F6D9628469189715575E55B236B43FD49@IRSMSX104.ger.corp.intel.com>

On 6/4/19 2:36 PM, Metzger, Markus T wrote:
> Hello Felix,
>
>> With this patch a default ptwrite listener is registered upon start of GDB.
>> It prints the plain ptwrite payload as hex.  The default listener can be
>> overwritten by registering a custom listener in python or by registering
>> "None", for no output at all.  Registering a listener function creates per
>> thread copies to allow unique internal states per thread.
>>
>> 2019-05-29  Felix Willgerodt  <felix.willgerodt@intel.com>
>>
>> gdb/ChangeLog:
>> * btrace.c (ftrace_add_pt): Add call to
>> apply_ext_lang_ptwrite_listener.
>> * btrace.h (btrace_thread_info): New member ptw_listener.
>> * data-directory/Makefile.in: Add ptwrite.py.
>> * extension-priv.h (struct extension_language_ops): New member
>> apply_ptwrite_listener.
>> * extension.c (apply_ext_lang_ptwrite_listener): New function.
>> * extension.h (apply_ext_lang_ptwrite_listener): New declaration.
>> * guile/guile.c (guile_extension_ops): Add
>> gdbscm_load_ptwrite_listener.
>> * python/lib/gdb/ptwrite.py: New file.
>> * python/py-record-btrace.c (recpy_initialize_listener,
>> get_ptwrite_listener): New function.
>> * python/py-record-btrace.h (recpy_initialize_listener): New
>> declaration.
>> * python/py-record.c (gdbpy_load_ptwrite_listener): New function.
>> * python/python-internal.h (gdbpy_load_ptwrite_listener): New
>> declaration.
>> * python/python.c (python_extension_ops): New member
>> gdbpy_load_ptwrite_listener.
>>
>> ---
>>   gdb/btrace.c                   |  3 ++
>>   gdb/btrace.h                   |  3 ++
>>   gdb/data-directory/Makefile.in |  1 +
>>   gdb/extension-priv.h           |  4 ++
>>   gdb/extension.c                | 24 ++++++++++
>>   gdb/extension.h                |  3 ++
>>   gdb/guile/guile.c              |  1 +
>>   gdb/python/lib/gdb/ptwrite.py  | 83
>> ++++++++++++++++++++++++++++++++++
>>   gdb/python/py-record-btrace.c  | 40 ++++++++++++++++
>>   gdb/python/py-record-btrace.h  |  3 ++
>>   gdb/python/py-record.c         | 29 ++++++++++++
>>   gdb/python/python-internal.h   |  3 ++
>>   gdb/python/python.c            |  2 +
>>   13 files changed, 199 insertions(+)
>>   create mode 100644 gdb/python/lib/gdb/ptwrite.py

Markus> When registering a new PTWRITE listener, could GDB check the libipt version and give
Markus> an error if it does not support PTW?

In the current design GDB doesn't know if a there is a new listener (different to the default),
until it needs to use it. We would need to expose the libipt version somehow in python.
Not sure how that should look like, in CLI we only have it exposed in "maintenance info btrace".


>> @@ -1308,6 +1309,8 @@ ftrace_add_pt (struct btrace_thread_info *btinfo,
>>     uint64_t offset;
>>     int status;
>>
>> +  apply_ext_lang_ptwrite_listener (inferior_ptid);

Markus > We may decode the trace in chunks by calling ftrace_add_pt () multiple times.
Markus > This would need to preserve (the state of) the installed listener.

The state is already preserved. This just fetches the (C++) pointer to
be able to call the listener from GDB. If the listener wasn't changed,
the same pointer/object will be fetched as in the first call to ftrace_add_pt
().


>> @@ -0,0 +1,83 @@
>> +# Ptwrite utilities.
>> +# Copyright (C) 2018 Free Software Foundation, Inc.

Markus> It's 2019, meanwhile.

Fixed.

>> +
>> +# This program is free software; you can redistribute it and/or modify
>> +# it under the terms of the GNU General Public License as published by
>> +# the Free Software Foundation; either version 3 of the License, or
>> +# (at your option) any later version.
>> +#
>> +# This program is distributed in the hope that it will be useful,
>> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> +# GNU General Public License for more details.
>> +#
>> +# You should have received a copy of the GNU General Public License
>> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
>> +
>> +"""Utilities for working with ptwrite listeners."""
>> +
>> +import gdb
>> +from copy import deepcopy
>> +
>> +
>> +def default_listener(payload, ip):

Markus> I somehow expected some PtwritePrinter class.

I don't see any advantage of classifying the default one. And as we allow every
callable, I don't see anything else we need to provide here. Please elaborate if you do.


>> +    """Default listener that is active upon starting GDB."""
>> +    return "payload: {:#x}".format(payload)

Markus> Should we return the payload (in hex) without the prefix?

I don't really have a preference. Done.


>> @@ -735,3 +735,32 @@ gdbpy_stop_recording (PyObject *self, PyObject *args)
>>
>>     Py_RETURN_NONE;
>>   }
>> +
>> +/* Used for registering the default ptwrite listener to the current thread.  A
>> +   pointer to this function is stored in the python extension interface.  */
>> +
>> +enum ext_lang_bt_status
>> +gdbpy_load_ptwrite_listener (const struct extension_language_defn *extlang,
>> +     ptid_t inferior_ptid)

Markus> PTWRITE is very PT specific.  Any chance this could go into py-record-btrace.c?

Done.

>> +{
>> +  struct gdbarch *gdbarch = NULL;
>> +
>> +  if (!gdb_python_initialized)
>> +    return EXT_LANG_BT_NO_FILTERS;
>> +
>> +  try
>> +    {
>> +      gdbarch = target_gdbarch ();
>> +    }
>> +  catch (const gdb_exception &except)
>> +    {
>> +      /* Let gdb try to print the stack trace.  */
>> +      return EXT_LANG_BT_NO_FILTERS;

Markus> I fail to understand the comment.

I copied it from gdbpy_apply_frame_filter() when creating the function. Removed.

Thanks,
Felix
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

  reply	other threads:[~2021-06-14 14:53 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-29  8:48 [PATCH 00/10] Extensions for PTWRITE felix.willgerodt
2019-05-29  8:48 ` [PATCH 10/10] btrace: Extend event decoding for ptwrite felix.willgerodt
2019-05-29 14:53   ` Eli Zaretskii
2019-06-04 12:37   ` Metzger, Markus T
2021-06-14 14:53     ` Willgerodt, Felix
2019-05-29  8:48 ` [PATCH 05/10] python: Introduce gdb.RecordAuxiliary class felix.willgerodt
2019-05-29 14:42   ` Eli Zaretskii
2019-06-04 12:36   ` Metzger, Markus T
2021-06-14 14:53     ` Willgerodt, Felix
2019-05-29  8:48 ` [PATCH 01/10] btrace: Introduce auxiliary instructions felix.willgerodt
2019-05-29 14:39   ` Eli Zaretskii
2019-06-04 12:35   ` Metzger, Markus T
2019-05-29  8:48 ` [PATCH 04/10] btrace: Handle stepping and goto for " felix.willgerodt
2019-06-04 12:35   ` Metzger, Markus T
2021-06-14 14:53     ` Willgerodt, Felix
2019-05-29  8:48 ` [PATCH 02/10] btrace: Enable auxiliary instructions in record instruction-history felix.willgerodt
2019-06-04 12:35   ` Metzger, Markus T
2021-06-14 14:53     ` Willgerodt, Felix
2019-05-29  8:48 ` [PATCH 07/10] btrace, linux: Enable ptwrite packets felix.willgerodt
2019-06-04 12:36   ` Metzger, Markus T
2021-06-14 14:53     ` Willgerodt, Felix
2019-05-29  8:48 ` [PATCH 08/10] btrace, python: Enable ptwrite listener registration felix.willgerodt
2019-06-04 12:36   ` Metzger, Markus T
2021-06-14 14:53     ` Willgerodt, Felix [this message]
2019-05-29  8:48 ` [PATCH 09/10] btrace, python: Enable calling the ptwrite listener felix.willgerodt
2019-06-04 12:37   ` Metzger, Markus T
2021-06-14 14:53     ` Willgerodt, Felix
2019-05-29  8:48 ` [PATCH 03/10] btrace: Enable auxiliary instructions in record function-call-history felix.willgerodt
2019-05-29 14:40   ` Eli Zaretskii
2019-06-04 12:35   ` Metzger, Markus T
2021-06-14 14:53     ` Willgerodt, Felix
2021-06-16  9:13       ` Metzger, Markus T
2021-06-16 10:03         ` Willgerodt, Felix
2021-06-16 10:16           ` Metzger, Markus T
2019-05-29  8:48 ` [PATCH 06/10] python: Add clear_trace() to gdb.Record felix.willgerodt
2019-05-29 14:41   ` Eli Zaretskii
2019-06-04 12:36   ` Metzger, Markus T
2021-06-14 14:53     ` Willgerodt, Felix

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=b1a208bd39e2497382ef591c79aa9c42@intel.com \
    --to=felix.willgerodt@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=markus.t.metzger@intel.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).