Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Metzger, Markus T" <markus.t.metzger@intel.com>
To: "Wiederhake, Tim" <tim.wiederhake@intel.com>,
	"gdb-patches@sourceware.org"	<gdb-patches@sourceware.org>
Cc: "palves@redhat.com" <palves@redhat.com>
Subject: RE: [PATCH v3 6/8] python: Implement btrace Python bindings for record history.
Date: Tue, 29 Nov 2016 15:48:00 -0000	[thread overview]
Message-ID: <A78C989F6D9628469189715575E55B2340013195@IRSMSX104.ger.corp.intel.com> (raw)
In-Reply-To: <1479743318-24523-7-git-send-email-tim.wiederhake@intel.com>

> -----Original Message-----
> From: Wiederhake, Tim
> Sent: Monday, November 21, 2016 4:49 PM
> To: gdb-patches@sourceware.org
> Cc: palves@redhat.com; Metzger, Markus T <markus.t.metzger@intel.com>
> Subject: [PATCH v3 6/8] python: Implement btrace Python bindings for record
> history.
> 
> This patch implements the gdb.Record Python object methods and fields for
> record target btrace.  Additionally, add a stub for record target full.
> 
> 2016-11-21  Tim Wiederhake  <tim.wiederhake@intel.com>
> 
> gdb/ChangeLog:
> 
> 	* Makefile.in (SUBDIR_PYTHON_OBS): Add py-btrace.o.
> 	(SUBDIR_PYTHON_SRCS): Add py-btrace.c.
> 	* python/py-btrace.c: New file.
> 	* python/py-btrace.h: New file.
> 	* python/python-internal.h (gdbpy_initialize_btrace): New export.
> 	* python/python.c (_initialize_python): Add gdbpy_initialize_btrace.
> 	* record-btrace.c: Add conditional includes for python/py-record.h
> 	and python/py-btrace.h
> 	(record_btrace_python_interface): New function.
> 	(init_record_btrace_ops): Add record_btrace_python_interface.
> 	* record-full.c: Add conditional include for python/py-record.h.
> 	(record_full_python_interface): New function.
> 	(init_record_full_ops): Add record_full_python_interface.


> +/* Python object for btrace records.  This can either be an instruction or a
> +   function call segment, depending on the chosen type.  */

That's not the object for a btrace recording, right?  Maybe just omit the first sentence
and say right away that this can either be a btrace instruction or function segment.


> +  if (!PySlice_Check (value))
> +    return PyErr_Format (PyExc_TypeError, _("Index must be int or slice."));
> +
> +  if (0 != PySlice_GetIndicesEx (BTPY_PYSLICE (value), length, &start, &stop,
> +				 &step, &slicelength))
> +    return NULL;
> +
> +  return btpy_list_new (obj->ptid, obj->first + obj->step * start,
> +			obj->first + obj->step * stop, obj->step * step,
> +			obj->element_type);

Is PySlice_GetIndicesEx checking that the above operations can't overflow?


> +/* Implementation of BtraceList.count (self, value) -> int.  */
> +
> +static PyObject *
> +btpy_list_count (PyObject *self, PyObject *value)
> +{
> +  const LONGEST index = btpy_list_position (self, value);
> +
> +  if (index < 0)
> +    return PyInt_FromLong (0);
> +  else
> +    return PyInt_FromLong (1);
> +}

Hmmm, we need instruction instances to be unique for "record goto".  OTOH it
might be nice to count the number of occurrences of a given instruction at a given
PC.  Would it make sense to define equality as "same PC" for the purpose of count ()?


> +/* Implementation of
> +   BtraceRecord.instruction_history [list].  */
> +
> +static PyObject *
> +recpy_bt_instruction_history (PyObject* self, void* closure)
> +{
> +  struct thread_info * const tinfo = find_thread_ptid (inferior_ptid);
> +  struct btrace_insn_iterator iterator;
> +  unsigned long first = 0;
> +  unsigned long last = 0;
> +
> +   if (tinfo == NULL)
> +     Py_RETURN_NONE;
> +
> +   btrace_fetch (tinfo);
> +
> +   if (btrace_is_empty (tinfo))
> +     Py_RETURN_NONE;
> +
> +   btrace_insn_begin (&iterator, &tinfo->btrace);
> +   first = btrace_insn_number (&iterator);
> +
> +   btrace_insn_end (&iterator, &tinfo->btrace);
> +   last = btrace_insn_number (&iterator);
> +
> +   return btpy_list_new (inferior_ptid, first, last, 1, &btpy_insn_type);

IIRC last was included in the list.  The btrace end iterator points one past the
end of the list.  Is this intentional to include the current instruction?


> +/* Implementation of
> +   BtraceRecord.function_call_history [list].  */
> +
> +static PyObject *
> +recpy_bt_function_call_history (PyObject* self, void* closure)
> +{
> +    struct thread_info * const tinfo = find_thread_ptid (inferior_ptid);
> +    struct btrace_call_iterator iterator;
> +    unsigned long first = 0;
> +    unsigned long last = 0;
> +
> +    if (tinfo == NULL)
> +      Py_RETURN_NONE;
> +
> +    btrace_fetch (tinfo);
> +
> +    if (btrace_is_empty (tinfo))
> +      Py_RETURN_NONE;
> +
> +    btrace_call_begin (&iterator, &tinfo->btrace);
> +    first = btrace_call_number (&iterator);
> +
> +    btrace_call_end (&iterator, &tinfo->btrace);
> +    last = btrace_call_number (&iterator);
> +
> +    return btpy_list_new (inferior_ptid, first, last, 1, &btpy_call_type);

Same here.


> +struct PyGetSetDef btpy_insn_getset[] = {
> +  { "number", btpy_number, NULL, "instruction number", NULL},
> +  { "error", btpy_insn_error, NULL, "error number for gaps", NULL},
> +  { "symbol", btpy_insn_symbol, NULL, "associated symbol", NULL},
> +  { "pc", btpy_insn_pc, NULL, "instruction address", NULL},
> +  { "data", btpy_insn_data, NULL, "raw instruction data", NULL},
> +  { "decoded", btpy_insn_decode, NULL, "decoded instruction", NULL},

Doesn't this also give the error string for gaps?


> +  { "size", btpy_insn_size, NULL, "instruction size in byte", NULL},
> +  { "is_speculative", btpy_insn_is_speculative, NULL, "if the instruction was \
> +executed speculatively", NULL},
> +  {NULL}
> +};
> +
> +/* BtraceFunctionCall members.  */
> +
> +static PyGetSetDef btpy_call_getset[] = {
> +  { "number", btpy_number, NULL, "function call number", NULL},
> +  { "level", btpy_call_level, NULL, "call stack level", NULL},
> +  { "symbol", btpy_call_symbol, NULL, "associated line and symbol", NULL},
> +  { "instructions", btpy_call_instructions, NULL, "list of instructions in \
> +this function call", NULL},

Shouldn't this be "function segment" instead of "function call"?



The patch looks otherwise good to me but we need to find a maintainer to
approve the patch.

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, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


  reply	other threads:[~2016-11-29 15:48 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-21 15:49 [PATCH v3 0/8] Python bindings for btrace recordings Tim Wiederhake
2016-11-21 15:49 ` [PATCH v3 4/8] Add record_start function Tim Wiederhake
2016-11-29 15:47   ` Metzger, Markus T
2016-11-21 15:49 ` [PATCH v3 7/8] python: Add tests for record Python bindings Tim Wiederhake
2016-11-29 15:48   ` Metzger, Markus T
2016-11-21 15:49 ` [PATCH v3 1/8] btrace: Count gaps as one instruction explicitly Tim Wiederhake
2016-11-29 15:47   ` Metzger, Markus T
2016-11-21 15:49 ` [PATCH v3 5/8] python: Create Python bindings for record history Tim Wiederhake
2016-11-29 15:48   ` Metzger, Markus T
2016-11-21 15:49 ` [PATCH v3 3/8] btrace: Use binary search to find instruction Tim Wiederhake
2016-11-29 15:47   ` Metzger, Markus T
2016-11-21 15:49 ` [PATCH v3 8/8] Add documentation for new instruction record Python bindings Tim Wiederhake
2016-11-29 15:48   ` Metzger, Markus T
2016-11-29 17:32     ` Eli Zaretskii
2016-11-21 15:49 ` [PATCH v3 6/8] python: Implement btrace Python bindings for record history Tim Wiederhake
2016-11-29 15:48   ` Metzger, Markus T [this message]
2016-11-21 15:49 ` [PATCH v3 2/8] btrace: Export btrace_decode_error function Tim Wiederhake
2016-11-29 15:47   ` Metzger, Markus T
2016-11-29 15:49 ` [PATCH v3 0/8] Python bindings for btrace recordings Metzger, Markus T
2016-12-01  0:46 [PATCH v3 6/8] python: Implement btrace Python bindings for record history Doug Evans

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=A78C989F6D9628469189715575E55B2340013195@IRSMSX104.ger.corp.intel.com \
    --to=markus.t.metzger@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    --cc=tim.wiederhake@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