Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Kieran Bingham <kieran.bingham@linaro.org>
To: gdb@sourceware.org
Cc: Yao Qi <yao.qi@linaro.org>, Peter Griffin <peter.griffin@linaro.org>
Subject: [RFC] Target Layer Python Interface
Date: Fri, 29 Jan 2016 12:33:00 -0000	[thread overview]
Message-ID: <56AB5C11.1020800@linaro.org> (raw)

While investigating how to get Python to define the threads presented by
the application layer (in my instance the linux kernel) I found that I
could create threads with a call from Python, (by writing a hook through
the inferior object)

However, whilst these threads were added, they were immediately removed
by the next call to (target).to_update_thread_list()


This has led me to believe I should create a Python Target layer
interface, which I have started, and have been able to register a
target, and provide Python bindings so that (currently _to_thread_name)
calls into the python layer object, and returns a new name.


My intention is that this can be extended to provide the whole set of
target operations allowing me to implement much of the Linux Kernel
Debugger interface in Python.


Through this layer, we can even tackle some of the issues with memory
address spaces, by adding appropriate hooks to adjust MMU context, or
interpret page tables through the relevant target_ops hooks.


Some of the interface can even hopefully be autogenerated by a
make-target-delegate equivalent

This layer interface, will mean that I can provide a Linux Thread
Awareness layer to implement a thread_stratum layer, and can even go
further to provide extra layers for other functionality later.

With a example implementation looking like the start of this:

======================================================================
class LxAwarenessTarget(gdb.Target):
    """ Provide a Linux Awareness Target Layer

This will provide hooks for our Thread implementation, and later
extra architecture specific target layers to handle memory """

    def __init__(self):
        self.shortname = "LxThreads"
        self.longname = "Linux Thread Integration Layer"
        super(LxAwarenessTarget, self).__init__(gdb.Stratums.thread)

    def to_thread_name(self, gdbthread):
        return "A thread"

    ...

(gdb) maintenance print target-stack
The current target stack is:
  - LxThreads (Linux Thread Integration Layer)
  - remote (Remote serial target in gdb-specific protocol)
  - exec (Local exec file)
  - None (None)

(gdb) info threads
  Id   Target Id         Frame
  2    Thread 2 "A thread" (CPU#1 [halted ]) default_idle ()
    at /home/linaro/sources/linux/arch/x86/kernel/process.c:305
* 1    Thread 1 "A thread" (CPU#0 [halted ]) default_idle ()
    at /home/linaro/sources/linux/arch/x86/kernel/process.c:305
======================================================================



By implementing this as a layer, it will also allow other
implementations from OS's or targets to define their specific
implementation detail in their source trees


Before I head too much further, I wanted to ask the opinions of the
community as to whether this is an acceptable interface to implement, or
if it opens up too much of the GDB internals, to external dependencies.

Whilst the target layer may be defined as 'fairly' stable - It has
undergone changes, and this may cause issues if exposed to an external
interface.

We could of course tackle this by providing a versioned API which would
allow adaptation in the Python objects, but I thought it was a big
enough question that it should be posed to a wider audience (wider than
just me!)

Regards
--
Kieran


             reply	other threads:[~2016-01-29 12:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-29 12:33 Kieran Bingham [this message]
2016-01-31 15:21 ` Phil Muldoon
2016-02-01 18:19   ` Kieran Bingham
2016-02-04 22:16     ` Ales Novak
2016-02-05 16:36       ` Kieran Bingham
2016-02-05 16:38         ` Jeff Mahoney
2016-02-05 16:47           ` Kieran Bingham
2016-02-05 17:06             ` Kieran Bingham

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=56AB5C11.1020800@linaro.org \
    --to=kieran.bingham@linaro.org \
    --cc=gdb@sourceware.org \
    --cc=peter.griffin@linaro.org \
    --cc=yao.qi@linaro.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