This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RE: [PATCH 08/10] btrace, python: Enable ptwrite listener registration.
- From: "Metzger, Markus T" <markus dot t dot metzger at intel dot com>
- To: "Willgerodt, Felix" <felix dot willgerodt at intel dot com>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Tue, 4 Jun 2019 12:36:35 +0000
- Subject: RE: [PATCH 08/10] btrace, python: Enable ptwrite listener registration.
- References: <1559119673-30516-1-git-send-email-felix.willgerodt@intel.com> <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