mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Roland Hieber <rhi@pengutronix.de>
To: Rouven Czerwinski <r.czerwinski@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 3/3] add gdb helper scripts to load barebox symbols
Date: Thu, 6 Jun 2019 20:35:57 +0200	[thread overview]
Message-ID: <20190606183557.enmjhh34jzialmwq@pengutronix.de> (raw)
In-Reply-To: <20190604143851.11928-3-r.czerwinski@pengutronix.de>

On Tue, Jun 04, 2019 at 04:38:53PM +0200, Rouven Czerwinski wrote:
> Add a gdb script with two helper functions which use the new
> pbl_barebox_break symbol to calculate the current barebox load address
> on the device and loads a barebox ELF file to this address.
> 
> Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
> ---
>  Documentation/user/debugging.rst   | 21 +++++++++++
>  Documentation/user/user-manual.rst |  1 +
>  common/Kconfig                     |  9 +++++
>  scripts/gdb/helper.py              | 60 ++++++++++++++++++++++++++++++
>  4 files changed, 91 insertions(+)
>  create mode 100644 Documentation/user/debugging.rst
>  create mode 100644 scripts/gdb/helper.py
> 
> diff --git a/Documentation/user/debugging.rst b/Documentation/user/debugging.rst
> new file mode 100644
> index 0000000000..15cb439043
> --- /dev/null
> +++ b/Documentation/user/debugging.rst
> @@ -0,0 +1,21 @@
> +Debugging with OpenOCD
> +======================
> +
> +Barebox can be configured to break on prebootloader and main barebox entry. This
> +breakpoint can not be resumed and will stop the board to allow the user to
> +attach a JTAG debugger with OpenOCD. Additionally, barebox provides helper
> +scripts to load the symbols from the ELF binaries.
> +The python scripts require `pyelftools`.
> +To load the scripts into your gdb session, run the following command in the
> +barebox directory:
> +
> +.. code-block:: none
> +
> +    (gdb) source scripts/gdb/helper.py
> +
> +This makes two new commands available in gdb, `bb-load-symbols` and
> +`bb-skip-break`. `bb-load-symbols` can load either the main `barebox` file or
> +one of the .pbl files in the image directories. The board needs to be stopped in
> +either the prebootloader or main barebox breakpoint, and gdb needs to be
> +connected to OpenOCD. To continue booting the board, `bb-skip-break` jumps over
> +the breakpoint and continues the barebox execution.
> diff --git a/Documentation/user/user-manual.rst b/Documentation/user/user-manual.rst
> index 516b760b1b..f04981c3f0 100644
> --- a/Documentation/user/user-manual.rst
> +++ b/Documentation/user/user-manual.rst
> @@ -33,6 +33,7 @@ Contents:
>     system-reset
>     state
>     random
> +   debugging
>  
>  * :ref:`search`
>  * :ref:`genindex`
> diff --git a/common/Kconfig b/common/Kconfig
> index 4124857a0a..c766e1ef64 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -1252,6 +1252,15 @@ config PBL_BREAK
>  	  If this enabled, barebox will be compiled with BKPT instruction
>  	  on early pbl init. This option be used only with JTAG debugger!
>  
> +config GDB_SCRIPTS
> +	bool "Provide GDB scripts for barebox debugging"
> +	help
> +	  This creates the required links to GDB helper scripts in the
> +	  build directory. If you load barebox into gdb, the helper
> +	  scripts will be automatically imported by gdb as well, and
> +	  additional functions are available to analyze a Linux kernel
> +	  instance.
> +
>  endmenu

This symbol is not used in any way, as far as I can see.

 - Roland

>  
>  config HAS_DEBUG_LL
> diff --git a/scripts/gdb/helper.py b/scripts/gdb/helper.py
> new file mode 100644
> index 0000000000..4041789890
> --- /dev/null
> +++ b/scripts/gdb/helper.py
> @@ -0,0 +1,60 @@
> +#!/usr/bin/env python
> +
> +import gdb
> +
> +try:
> +    from elftools.elf.elffile import ELFFile
> +    from elftools.common.exceptions import ELFError
> +except ImportError:
> +    gdb.write("The barebox helper requires pyelftools\n", gdb.STDERR)
> +    exit(1)
> +
> +
> +class BBSymbols(gdb.Command):
> +
> +    def __init__(self):
> +        super(BBSymbols, self).__init__("bb-load-symbols", gdb.COMMAND_FILES,
> +                                        gdb.COMPLETE_FILENAME)
> +
> +    def invoke(self, argument, from_tty):
> +        path = argument
> +        f = open(path, 'rb')
> +
> +        try:
> +            elf = ELFFile(f)
> +        except ELFError:
> +            gdb.write("Selected file is not an ELF file\n", gdb.STDERR)
> +            return
> +
> +        section = elf.get_section_by_name(".symtab")
> +        if section is None:
> +            gdb.write("Section .symtab not found\n", gdb.STDERR)
> +            return
> +        symbol = section.get_symbol_by_name("pbl_barebox_break")
> +        if not symbol:
> +            gdb.write("Symbol pbl_barebox_break in section {} in file {} not found\n"
> +                      .format(section.name, self.path), gdb.STDERR)
> +            return
> +        symbol = symbol[0]
> +        pc = gdb.parse_and_eval("$pc")
> +        symbol_address = int(symbol.entry.st_value)
> +        address = int(pc) - symbol_address + 1
> +        gdb.execute("symbol-file")
> +        gdb.execute("add-symbol-file {} {}".format(path, address))
> +
> +
> +BBSymbols()
> +
> +
> +class BBSkip(gdb.Command):
> +
> +    def __init__(self):
> +        super(BBSkip, self).__init__("bb-skip-break", gdb.COMMAND_BREAKPOINTS)
> +
> +    def invoke(self, arg, from_tty):
> +        pc = gdb.parse_and_eval("$pc")
> +        nop_address = int(pc) + 2
> +        gdb.execute("jump *{}".format(nop_address))
> +
> +
> +BBSkip()
> -- 
> 2.21.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Roland Hieber                     | r.hieber@pengutronix.de     |
Pengutronix e.K.                  | https://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim | Phone: +49-5121-206917-5086 |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      reply	other threads:[~2019-06-06 18:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-04 14:38 [PATCH 1/3] remove CONFIG_DEBUG_INFO Rouven Czerwinski
2019-06-04 14:38 ` [PATCH 2/3] add CONFIG_PBL_BREAK option Rouven Czerwinski
2019-06-07  6:33   ` Sascha Hauer
2019-06-04 14:38 ` [PATCH 3/3] add gdb helper scripts to load barebox symbols Rouven Czerwinski
2019-06-06 18:35   ` Roland Hieber [this message]

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=20190606183557.enmjhh34jzialmwq@pengutronix.de \
    --to=rhi@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=r.czerwinski@pengutronix.de \
    /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