Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Jan Vrany <jan.vrany@labware.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb: skip objfiles with no BFD in DWARF unwinder
Date: Tue, 5 Apr 2022 10:46:16 -0400	[thread overview]
Message-ID: <22e6f3e9-e065-e90d-7d98-9cf20aa30144@simark.ca> (raw)
In-Reply-To: <20220405100429.188136-1-jan.vrany@labware.com>

On 2022-04-05 06:04, Jan Vrany via Gdb-patches wrote:
> While playing with JIT reader I experienced GDB to crash on null-pointer
> dereference when stepping through non-jitted code.
>
> The problem was that dwarf2_frame_find_fde () assumed that all objfiles
> have BFD but that's not always true. To address this problem, this
> commit skips such objfiles.
>
> As for the test, I initially tried to use temporary breakpoint and then
> 'continue' to get out of the jitted code but this for some reason did
> not trigger the crash. Using 'finish' to get out of jitted code followed
> by 'next' triggered it.
> ---
>  gdb/dwarf2/frame.c                    |  3 +++
>  gdb/objfiles.h                        |  4 +++-
>  gdb/testsuite/gdb.base/jit-reader.exp | 10 ++++++++++
>  3 files changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/gdb/dwarf2/frame.c b/gdb/dwarf2/frame.c
> index 5878d72f922..514ae8c694f 100644
> --- a/gdb/dwarf2/frame.c
> +++ b/gdb/dwarf2/frame.c
> @@ -1565,6 +1565,9 @@ dwarf2_frame_find_fde (CORE_ADDR *pc, dwarf2_per_objfile **out_per_objfile)
>        CORE_ADDR offset;
>        CORE_ADDR seek_pc;
>
> +      if (objfile->obfd == nullptr)
> +	continue;

Ok, I presume that this is the case only for JIT-ed objfiles whose
debuginfo was created using the JIT debug info reader API.  If the JIT
engine produced an executable file in memory with DWARF in it and we
consumed it, then I suppose that objfile will have a bfd, since it was
opened and parsed using bfd.

> +
>        comp_unit *unit = find_comp_unit (objfile);
>        if (unit == NULL)
>  	{
> diff --git a/gdb/objfiles.h b/gdb/objfiles.h
> index 8bd76705688..429dea1da4c 100644
> --- a/gdb/objfiles.h
> +++ b/gdb/objfiles.h
> @@ -636,7 +636,9 @@ struct objfile
>    struct compunit_symtab *compunit_symtabs = nullptr;
>
>    /* The object file's BFD.  Can be null if the objfile contains only
> -     minimal symbols, e.g. the run time common symbols for SunOS4.  */
> +     minimal symbols (e.g. the run time common symbols for SunOS4) or
> +     if the objfile is a dynamic objfile (e.g. created by JIT reader
> +     API).  */
>
>    bfd *obfd;
>
> diff --git a/gdb/testsuite/gdb.base/jit-reader.exp b/gdb/testsuite/gdb.base/jit-reader.exp
> index d94360cd7d9..0de552b1ce5 100644
> --- a/gdb/testsuite/gdb.base/jit-reader.exp
> +++ b/gdb/testsuite/gdb.base/jit-reader.exp
> @@ -271,6 +271,16 @@ proc jit_reader_test {} {
>  		 "#1 ${any} in main ${any}" \
>  		]
>      }
> +
> +    # check that the DWARF unwinder does not crash in presence of

Capital C to "check".

> +    # JIT objfiles.
> +    gdb_test "fin" \
> +	[multi_line \
> +		 "Run till exit from ${any} jit_function_stack_mangle ${any}" \
> +		 "main ${any} at ${any}.*" \
> +		]
> +    gdb_test "bt" "#0  main ${any} at ${any}"
> +    gdb_test "next"

Please take in consideration Lancelot's comment, the patch LGTM with
that feedback addressed.

Simon

  parent reply	other threads:[~2022-04-05 14:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-05 10:04 Jan Vrany via Gdb-patches
2022-04-05 14:19 ` Lancelot SIX via Gdb-patches
2022-04-05 14:46 ` Simon Marchi [this message]
2022-04-06 17:50   ` Jan Vrany via Gdb-patches
2022-04-05 19:08 ` Pedro Alves
2022-04-06 18:06   ` Jan Vrany via Gdb-patches
2022-04-06 18:55   ` [PATCH v2] " Jan Vrany via Gdb-patches
2022-12-07 11:07     ` Jan Vraný via Gdb-patches
2022-12-07 16:07     ` Simon Marchi via Gdb-patches

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=22e6f3e9-e065-e90d-7d98-9cf20aa30144@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.vrany@labware.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