From: "Metzger, Markus T" <markus.t.metzger@intel.com>
To: "Willgerodt, Felix" <felix.willgerodt@intel.com>,
"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: RE: [PATCH 08/10] btrace, python: Enable ptwrite listener registration.
Date: Tue, 04 Jun 2019 12:36:00 -0000 [thread overview]
Message-ID: <A78C989F6D9628469189715575E55B236B43FD49@IRSMSX104.ger.corp.intel.com> (raw)
In-Reply-To: <1559119673-30516-9-git-send-email-felix.willgerodt@intel.com>
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
When registering a new PTWRITE listener, could GDB check the libipt version and give
an error if it does not support PTW?
> @@ -1308,6 +1309,8 @@ ftrace_add_pt (struct btrace_thread_info *btinfo,
> uint64_t offset;
> int status;
>
> + apply_ext_lang_ptwrite_listener (inferior_ptid);
We may decode the trace in chunks by calling ftrace_add_pt () multiple times.
This would need to preserve (the state of) the installed listener.
> @@ -0,0 +1,83 @@
> +# Ptwrite utilities.
> +# Copyright (C) 2018 Free Software Foundation, Inc.
It's 2019, meanwhile.
> +
> +# 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):
I somehow expected some PtwritePrinter class.
> + """Default listener that is active upon starting GDB."""
> + return "payload: {:#x}".format(payload)
Should we return the payload (in hex) without the prefix?
> @@ -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)
PTWRITE is very PT specific. Any chance this could go into py-record-btrace.c?
> +{
> + 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;
I fail to understand the comment.
> + }
> +
> + gdbpy_enter enter_py (gdbarch, current_language);
> +
> + recpy_initialize_listener (inferior_ptid);
> +
> + return EXT_LANG_BT_OK;
> +}
Thanks,
Markus.
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
next prev parent reply other threads:[~2019-06-04 12:36 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 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 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 04/10] btrace: Handle stepping and goto for auxiliary instructions felix.willgerodt
2019-06-04 12:35 ` Metzger, Markus T
2021-06-14 14:53 ` Willgerodt, Felix
2019-05-29 8:48 ` [PATCH 01/10] btrace: Introduce " felix.willgerodt
2019-05-29 14:39 ` Eli Zaretskii
2019-06-04 12:35 ` Metzger, Markus T
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 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 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 08/10] btrace, python: Enable ptwrite listener registration felix.willgerodt
2019-06-04 12:36 ` Metzger, Markus T [this message]
2021-06-14 14:53 ` Willgerodt, Felix
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=A78C989F6D9628469189715575E55B236B43FD49@IRSMSX104.ger.corp.intel.com \
--to=markus.t.metzger@intel.com \
--cc=felix.willgerodt@intel.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).