gdb: Add switch to disable DWARF stack unwinders

Message ID 20180713134629.27011-1-andrew.burgess@embecosm.com
State New, archived
Headers

Commit Message

Andrew Burgess July 13, 2018, 1:46 p.m. UTC
  Add a maintenance command to disable the DWARF stack unwinders.
Normal users would not need this feature, but it is useful to allow
extended testing of fallback stack unwinding strategies, for example,
prologue scanners.

gdb/ChangeLog:

	* dwarf2-frame-tailcall.c (tailcall_frame_sniffer): Exit early if
	dwarf unwinders are disabled.
	* dwarf2-frame.c (dwarf2_frame_sniffer): Likewise.
	(dwarf2_frame_unwinders_enabled_p): Define.
	(dwarf2_append_unwinders): Enable dwarf unwinders when they are
	first registered.
	* dwarf2-frame.h (dwarf2_frame_unwinders_enabled_p): Declare.
	* dwarf2read.c: Add dwarf2-frame.h include.
	(show_dwarf_unwinders_enabled_p): New function.
	(_initialize_dwarf2_read): Register switch to control unwinder
	use.
	* NEWS: Document new feature.

gdb/doc/ChangeLog:

	* gdb.texinfo (Maintenance Commands): Add description of
	maintenance command to control dwarf unwinders.

gdb/testsuite/ChangeLog:

	* gdb.base/maint.exp: Add check that dwarf unwinders control flag
	is visible.
---
 gdb/ChangeLog                    | 15 +++++++++++++++
 gdb/NEWS                         |  6 ++++++
 gdb/doc/ChangeLog                |  5 +++++
 gdb/doc/gdb.texinfo              | 24 ++++++++++++++++++++++++
 gdb/dwarf2-frame-tailcall.c      |  3 +++
 gdb/dwarf2-frame.c               |  9 +++++++++
 gdb/dwarf2-frame.h               |  6 ++++++
 gdb/dwarf2read.c                 | 26 ++++++++++++++++++++++++++
 gdb/testsuite/ChangeLog          |  5 +++++
 gdb/testsuite/gdb.base/maint.exp |  4 ++++
 10 files changed, 103 insertions(+)
  

Comments

Eli Zaretskii July 13, 2018, 1:54 p.m. UTC | #1
> From: Andrew Burgess <andrew.burgess@embecosm.com>
> Cc: Andrew Burgess <andrew.burgess@embecosm.com>
> Date: Fri, 13 Jul 2018 14:46:29 +0100
> 
> Add a maintenance command to disable the DWARF stack unwinders.
> Normal users would not need this feature, but it is useful to allow
> extended testing of fallback stack unwinding strategies, for example,
> prologue scanners.

Thanks.

> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -7,6 +7,12 @@
>    can be passed using the '[ADDRESS]:PORT' notation, or the regular
>    'ADDRESS:PORT' method.
>  
> +* New commands
> +
> +maint set dwarf unwinders (on|off)
> +maint show dwarf unwinders
> +  Control whether DWARF unwinders can be used.
> +
>  *** Changes in GDB 8.2

OK for this part.

> +@cindex DWARF frame unwinders
> +Many targets that support DWARF debugging use @value{GDBN}'s DWARF
> +frame unwinders to build the backtrace.  Many of these targets will
> +also have a second mechanism for building the backtrace for use in
> +cases where DWARF information is not available, this second mechanism
> +is often an analysis of a functions prologue.
                             ^^^^^^^^^^^^^^^^^^
I think you meant "function's prologue" there.

The documentation parts are OK with the above nit fixed.
  
Tom Tromey July 13, 2018, 3:34 p.m. UTC | #2
>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> Add a maintenance command to disable the DWARF stack unwinders.
Andrew> Normal users would not need this feature, but it is useful to allow
Andrew> extended testing of fallback stack unwinding strategies, for example,
Andrew> prologue scanners.

Andrew> gdb/ChangeLog:

Maybe this should mention PR 8434, since it seems like part of that idea.

Tom
  
Andrew Burgess July 13, 2018, 10:37 p.m. UTC | #3
* Tom Tromey <tom@tromey.com> [2018-07-13 09:34:24 -0600]:

> >>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:
> 
> Andrew> Add a maintenance command to disable the DWARF stack unwinders.
> Andrew> Normal users would not need this feature, but it is useful to allow
> Andrew> extended testing of fallback stack unwinding strategies, for example,
> Andrew> prologue scanners.
> 
> Andrew> gdb/ChangeLog:
> 
> Maybe this should mention PR 8434, since it seems like part of that idea.

   PR8434: Add maintenance command to allow arbitrary unwinders to be
           enabled or disabled.

That's interesting.  I actually started working on a patch to do just
that.  In the end I stopped working on it because I was concerned that
the change would be too big, and of too little use to justify
merging.  The smaller change I posted got me the result I needed in a
much less intrusive change.

That said, if there is a wider interest in having this ability I'm
happy to dig out my old branch and get it ready for submission, but
I'd only want to put that effort in if this was a feature people would
like to see in GDB...

Thanks,
Andrew
  
Tom Tromey July 13, 2018, 10:57 p.m. UTC | #4
>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> That said, if there is a wider interest in having this ability I'm
Andrew> happy to dig out my old branch and get it ready for submission, but
Andrew> I'd only want to put that effort in if this was a feature people would
Andrew> like to see in GDB...

Yeah, I am not sure, your patch just reminded me of this.

Maybe if the DWARF patch goes in, the bug could be closed.
Given its age I would suppose this hasn't been needed very often.

Relatedly, somewhere I have a patch that adds a name to every unwinder,
so that you can tell what made the frame you're looking at.  This can be
handy when debugging unwinders.

Tom
  
Simon Marchi July 14, 2018, 1:11 a.m. UTC | #5
Hi Andrew,

On 2018-07-13 09:46 AM, Andrew Burgess wrote:
> diff --git a/gdb/dwarf2-frame-tailcall.c b/gdb/dwarf2-frame-tailcall.c
> index 1d3e1f445bb..f565a2eecc8 100644
> --- a/gdb/dwarf2-frame-tailcall.c
> +++ b/gdb/dwarf2-frame-tailcall.c
> @@ -318,6 +318,9 @@ tailcall_frame_sniffer (const struct frame_unwind *self,
>    int next_levels;
>    struct tailcall_cache *cache;
>  
> +  if (!dwarf2_frame_unwinders_enabled_p)
> +    return 0;
> +
>    /* Inner tail call element does not make sense for a sentinel frame.  */
>    next_frame = get_next_frame (this_frame);
>    if (next_frame == NULL)
> diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
> index 91e16cf024e..fdd41b360e6 100644
> --- a/gdb/dwarf2-frame.c
> +++ b/gdb/dwarf2-frame.c
> @@ -169,6 +169,9 @@ static CORE_ADDR read_encoded_value (struct comp_unit *unit, gdb_byte encoding,
>  				     CORE_ADDR func_base);
>  
>  
> +/* See dwarf2-frame.h.  */
> +int dwarf2_frame_unwinders_enabled_p = 0;

Is there any reason why you initialize this to 0, and set it to 1 in
dwarf2_append_unwinders?  It can produce some quite unexpected results, IMO:

(gdb) maintenance set dwarf unwinders off
(gdb) maintenance show dwarf unwinders
The DWARF stack unwinders are currently off.
(gdb) file test
Reading symbols from test...done.
(gdb) maintenance show dwarf unwinders
The DWARF stack unwinders are currently on.

Is there something wrong with initializing it to 1 directly and not touching
it after?

> +
>  /* Store the length the expression for the CFA in the `cfa_reg' field,
>     which is unused in that case.  */
>  #define cfa_exp_len cfa_reg
> @@ -1326,6 +1329,9 @@ static int
>  dwarf2_frame_sniffer (const struct frame_unwind *self,
>  		      struct frame_info *this_frame, void **this_cache)
>  {
> +  if (!dwarf2_frame_unwinders_enabled_p)
> +    return 0;
> +
>    /* Grab an address that is guarenteed to reside somewhere within the
>       function.  get_frame_pc(), with a no-return next function, can
>       end up returning something past the end of this function's body.
> @@ -1389,6 +1395,9 @@ dwarf2_append_unwinders (struct gdbarch *gdbarch)
>  
>    frame_unwind_append_unwinder (gdbarch, &dwarf2_frame_unwind);
>    frame_unwind_append_unwinder (gdbarch, &dwarf2_signal_frame_unwind);
> +
> +  /* Mark dwarf frame unwinders as enabled.  */
> +  dwarf2_frame_unwinders_enabled_p = 1;
>  }
>  
>  
> diff --git a/gdb/dwarf2-frame.h b/gdb/dwarf2-frame.h
> index 471281a2c3f..56c90be8ceb 100644
> --- a/gdb/dwarf2-frame.h
> +++ b/gdb/dwarf2-frame.h
> @@ -210,6 +210,12 @@ struct dwarf2_frame_state
>    bool armcc_cfa_offsets_reversed = false;
>  };
>  
> +/* When this is true the dwarf frame unwinders can be used if they are
> +   registered with the gdbarch.  Not all architectures can or do use the
> +   dwarf unwinders.  Setting this to true on a target that does not
> +   otherwise support the dwarf unwinders has no effect.  */

dwarf -> DWARF

> +extern int dwarf2_frame_unwinders_enabled_p;
> +
>  /* Set the architecture-specific register state initialization
>     function for GDBARCH to INIT_REG.  */
>  
> diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
> index 372f45ee175..b49d4d9fbbc 100644
> --- a/gdb/dwarf2read.c
> +++ b/gdb/dwarf2read.c
> @@ -90,6 +90,7 @@
>  #include <forward_list>
>  #include "rust-lang.h"
>  #include "common/pathstuff.h"
> +#include "dwarf2-frame.h"
>  
>  /* When == 1, print basic high level tracing messages.
>     When > 1, be more verbose.
> @@ -1423,6 +1424,19 @@ show_dwarf_max_cache_age (struct ui_file *file, int from_tty,
>  			    "DWARF compilation units is %s.\n"),
>  		    value);
>  }
> +
> +/* Handle 'maintenance show dwarf unwinders'.  */
> +
> +static void
> +show_dwarf_unwinders_enabled_p (struct ui_file *file, int from_tty,
> +				struct cmd_list_element *c,
> +				const char *value)
> +{
> +  fprintf_filtered (file,
> +		    _("The DWARF stack unwinders are currently %s.\n"),
> +		    value);
> +}

I don't think this is necessary, if you leave the "show" callback to NULL,
I think the message is clear enough:

(gdb) maintenance show dwarf unwinders
Whether the DWARF stack frame unwinders are used is on.

> +
>  
>  /* local function prototypes */
>  
> @@ -25363,6 +25377,18 @@ conversational style, when possible."),
>  			   &set_dwarf_cmdlist,
>  			   &show_dwarf_cmdlist);
>  
> +  add_setshow_boolean_cmd ("unwinders", class_obscure,
> +			   &dwarf2_frame_unwinders_enabled_p , _("\
> +Set whether the DWARF stack frame unwinders are used."), _("\
> +Show whether the DWARF stack frame unwinders are used."), _("\
> +When enabled the DWARF stack frame unwinders can be used for architectures\n\
> +that support the DWARF unwinders.  Enabling the dwarf unwinders for an\n\
> +architecture that doesn't support them will have no effect."),
> +			   NULL,
> +			   show_dwarf_unwinders_enabled_p,
> +			   &set_dwarf_cmdlist,
> +			   &show_dwarf_cmdlist);
> +

I think it would make sense to have the command registration in the same file as
dwarf2_frame_unwinders_enabled_p (dwarf2-frame.c).  set_dwarf_cmdlist/show_dwarf_cmdlist
would need to be exported though.  I guess their declarations can go in dwarf2read.h,
since they are defined in dwarf2read.c.

Simon
  
Andrew Burgess July 14, 2018, 8:35 p.m. UTC | #6
Simon,

Thanks for your review.  It all looks great, except for one follow up
question I have which is inline below...

* Simon Marchi <simark@simark.ca> [2018-07-13 21:11:38 -0400]:

> Hi Andrew,
> 
> On 2018-07-13 09:46 AM, Andrew Burgess wrote:
> > diff --git a/gdb/dwarf2-frame-tailcall.c b/gdb/dwarf2-frame-tailcall.c
> > index 1d3e1f445bb..f565a2eecc8 100644
> > --- a/gdb/dwarf2-frame-tailcall.c
> > +++ b/gdb/dwarf2-frame-tailcall.c
> > @@ -318,6 +318,9 @@ tailcall_frame_sniffer (const struct frame_unwind *self,
> >    int next_levels;
> >    struct tailcall_cache *cache;
> >  
> > +  if (!dwarf2_frame_unwinders_enabled_p)
> > +    return 0;
> > +
> >    /* Inner tail call element does not make sense for a sentinel frame.  */
> >    next_frame = get_next_frame (this_frame);
> >    if (next_frame == NULL)
> > diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
> > index 91e16cf024e..fdd41b360e6 100644
> > --- a/gdb/dwarf2-frame.c
> > +++ b/gdb/dwarf2-frame.c
> > @@ -169,6 +169,9 @@ static CORE_ADDR read_encoded_value (struct comp_unit *unit, gdb_byte encoding,
> >  				     CORE_ADDR func_base);
> >  
> >  
> > +/* See dwarf2-frame.h.  */
> > +int dwarf2_frame_unwinders_enabled_p = 0;
> 
> Is there any reason why you initialize this to 0, and set it to 1 in
> dwarf2_append_unwinders?  It can produce some quite unexpected results, IMO:
> 
> (gdb) maintenance set dwarf unwinders off
> (gdb) maintenance show dwarf unwinders
> The DWARF stack unwinders are currently off.
> (gdb) file test
> Reading symbols from test...done.
> (gdb) maintenance show dwarf unwinders
> The DWARF stack unwinders are currently on.
> 
> Is there something wrong with initializing it to 1 directly and not touching
> it after?
> 
> > +
> >  /* Store the length the expression for the CFA in the `cfa_reg' field,
> >     which is unused in that case.  */
> >  #define cfa_exp_len cfa_reg
> > @@ -1326,6 +1329,9 @@ static int
> >  dwarf2_frame_sniffer (const struct frame_unwind *self,
> >  		      struct frame_info *this_frame, void **this_cache)
> >  {
> > +  if (!dwarf2_frame_unwinders_enabled_p)
> > +    return 0;
> > +
> >    /* Grab an address that is guarenteed to reside somewhere within the
> >       function.  get_frame_pc(), with a no-return next function, can
> >       end up returning something past the end of this function's body.
> > @@ -1389,6 +1395,9 @@ dwarf2_append_unwinders (struct gdbarch *gdbarch)
> >  
> >    frame_unwind_append_unwinder (gdbarch, &dwarf2_frame_unwind);
> >    frame_unwind_append_unwinder (gdbarch, &dwarf2_signal_frame_unwind);
> > +
> > +  /* Mark dwarf frame unwinders as enabled.  */
> > +  dwarf2_frame_unwinders_enabled_p = 1;
> >  }
> >  
> >  
> > diff --git a/gdb/dwarf2-frame.h b/gdb/dwarf2-frame.h
> > index 471281a2c3f..56c90be8ceb 100644
> > --- a/gdb/dwarf2-frame.h
> > +++ b/gdb/dwarf2-frame.h
> > @@ -210,6 +210,12 @@ struct dwarf2_frame_state
> >    bool armcc_cfa_offsets_reversed = false;
> >  };
> >  
> > +/* When this is true the dwarf frame unwinders can be used if they are
> > +   registered with the gdbarch.  Not all architectures can or do use the
> > +   dwarf unwinders.  Setting this to true on a target that does not
> > +   otherwise support the dwarf unwinders has no effect.  */
> 
> dwarf -> DWARF
> 
> > +extern int dwarf2_frame_unwinders_enabled_p;
> > +
> >  /* Set the architecture-specific register state initialization
> >     function for GDBARCH to INIT_REG.  */
> >  
> > diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
> > index 372f45ee175..b49d4d9fbbc 100644
> > --- a/gdb/dwarf2read.c
> > +++ b/gdb/dwarf2read.c
> > @@ -90,6 +90,7 @@
> >  #include <forward_list>
> >  #include "rust-lang.h"
> >  #include "common/pathstuff.h"
> > +#include "dwarf2-frame.h"
> >  
> >  /* When == 1, print basic high level tracing messages.
> >     When > 1, be more verbose.
> > @@ -1423,6 +1424,19 @@ show_dwarf_max_cache_age (struct ui_file *file, int from_tty,
> >  			    "DWARF compilation units is %s.\n"),
> >  		    value);
> >  }
> > +
> > +/* Handle 'maintenance show dwarf unwinders'.  */
> > +
> > +static void
> > +show_dwarf_unwinders_enabled_p (struct ui_file *file, int from_tty,
> > +				struct cmd_list_element *c,
> > +				const char *value)
> > +{
> > +  fprintf_filtered (file,
> > +		    _("The DWARF stack unwinders are currently %s.\n"),
> > +		    value);
> > +}
> 
> I don't think this is necessary, if you leave the "show" callback to NULL,
> I think the message is clear enough:
> 
> (gdb) maintenance show dwarf unwinders
> Whether the DWARF stack frame unwinders are used is on.

I thought that was no longer the approved approach as the resulting
string is generated and not internationalised?

> 
> > +
> >  
> >  /* local function prototypes */
> >  
> > @@ -25363,6 +25377,18 @@ conversational style, when possible."),
> >  			   &set_dwarf_cmdlist,
> >  			   &show_dwarf_cmdlist);
> >  
> > +  add_setshow_boolean_cmd ("unwinders", class_obscure,
> > +			   &dwarf2_frame_unwinders_enabled_p , _("\
> > +Set whether the DWARF stack frame unwinders are used."), _("\
> > +Show whether the DWARF stack frame unwinders are used."), _("\
> > +When enabled the DWARF stack frame unwinders can be used for architectures\n\
> > +that support the DWARF unwinders.  Enabling the dwarf unwinders for an\n\
> > +architecture that doesn't support them will have no effect."),
> > +			   NULL,
> > +			   show_dwarf_unwinders_enabled_p,
> > +			   &set_dwarf_cmdlist,
> > +			   &show_dwarf_cmdlist);
> > +
> 
> I think it would make sense to have the command registration in the same file as
> dwarf2_frame_unwinders_enabled_p (dwarf2-frame.c).  set_dwarf_cmdlist/show_dwarf_cmdlist
> would need to be exported though.  I guess their declarations can go in dwarf2read.h,
> since they are defined in dwarf2read.c.
> 
> Simon

Thanks,
Andrew
  
Andrew Burgess July 14, 2018, 8:36 p.m. UTC | #7
* Tom Tromey <tom@tromey.com> [2018-07-13 16:57:35 -0600]:

> >>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:
> 
> Andrew> That said, if there is a wider interest in having this ability I'm
> Andrew> happy to dig out my old branch and get it ready for submission, but
> Andrew> I'd only want to put that effort in if this was a feature people would
> Andrew> like to see in GDB...
> 
> Yeah, I am not sure, your patch just reminded me of this.
> 
> Maybe if the DWARF patch goes in, the bug could be closed.
> Given its age I would suppose this hasn't been needed very often.
> 
> Relatedly, somewhere I have a patch that adds a name to every unwinder,
> so that you can tell what made the frame you're looking at.  This can be
> handy when debugging unwinders.

Great minds... :)

I have a similar patch as part of my "make all unwinders switchable"
series.  I agree it's a nice feature to be able to see who unwound
each frame.

Maybe I should clean it up and submit it...

Thanks,
Andrew

> 
> Tom
  
Simon Marchi July 14, 2018, 9:39 p.m. UTC | #8
On 2018-07-14 04:35 PM, Andrew Burgess wrote:
>> I don't think this is necessary, if you leave the "show" callback to NULL,
>> I think the message is clear enough:
>>
>> (gdb) maintenance show dwarf unwinders
>> Whether the DWARF stack frame unwinders are used is on.
> 
> I thought that was no longer the approved approach as the resulting
> string is generated and not internationalised?

Ah, I was not aware of that.  If you got that from a trustworthy source, then
I won't object :).

Simon
  
Tom Tromey July 16, 2018, 3:34 p.m. UTC | #9
>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> Great minds... :)

Andrew> I have a similar patch as part of my "make all unwinders switchable"
Andrew> series.  I agree it's a nice feature to be able to see who unwound
Andrew> each frame.

Andrew> Maybe I should clean it up and submit it...

I think it would be good, now that ordinary users can write unwinders
via Python.

Tom
  
Pedro Alves July 17, 2018, 1:23 p.m. UTC | #10
On 07/14/2018 10:39 PM, Simon Marchi wrote:
> On 2018-07-14 04:35 PM, Andrew Burgess wrote:
>>> I don't think this is necessary, if you leave the "show" callback to NULL,
>>> I think the message is clear enough:
>>>
>>> (gdb) maintenance show dwarf unwinders
>>> Whether the DWARF stack frame unwinders are used is on.
>>
>> I thought that was no longer the approved approach as the resulting
>> string is generated and not internationalised?
> 
> Ah, I was not aware of that.  If you got that from a trustworthy source, then
> I won't object :).
Here:

 void
 deprecated_show_value_hack (struct ui_file *ignore_file,
 			    int ignore_from_tty,
 			    struct cmd_list_element *c,
 			    const char *value)
 {
 ...
   /* Print doc minus "show" at start.  */
   print_doc_line (gdb_stdout, c->doc + 5);
 
That "c->doc + 5" trick only works in English.

Thanks,
Pedro Alves
  
Pedro Alves July 17, 2018, 1:36 p.m. UTC | #11
On 07/13/2018 02:46 PM, Andrew Burgess wrote:
> Add a maintenance command to disable the DWARF stack unwinders.
> Normal users would not need this feature, but it is useful to allow
> extended testing of fallback stack unwinding strategies, for example,
> prologue scanners.

I think a command to enable/disable unwinders is good, especially if
it supports all kinds of unwinders by name, but I thought I'd
also mention that the last time prologue testing came up, we ended up
with targeted unit tests.  See aarch64_analyze_prologue_test,
git commit 4d9a9006139d,
<https://sourceware.org/ml/gdb-patches/2016-12/msg00024.html>.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/NEWS b/gdb/NEWS
index acb9c34fb22..8b66cd8a9ad 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -7,6 +7,12 @@ 
   can be passed using the '[ADDRESS]:PORT' notation, or the regular
   'ADDRESS:PORT' method.
 
+* New commands
+
+maint set dwarf unwinders (on|off)
+maint show dwarf unwinders
+  Control whether DWARF unwinders can be used.
+
 *** Changes in GDB 8.2
 
 * The 'set disassembler-options' command now supports specifying options
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 2e9d76227c3..eb148cedef0 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -35802,6 +35802,30 @@ 
 memory will be used.  Setting it to zero disables caching, which will
 slow down @value{GDBN} startup, but reduce memory consumption.
 
+@kindex maint set dwarf unwinders
+@kindex maint show dwarf unwinders
+@item maint set dwarf unwinders
+@itemx maint show dwarf unwinders
+Control use of the DWARF frame unwinders.
+
+@cindex DWARF frame unwinders
+Many targets that support DWARF debugging use @value{GDBN}'s DWARF
+frame unwinders to build the backtrace.  Many of these targets will
+also have a second mechanism for building the backtrace for use in
+cases where DWARF information is not available, this second mechanism
+is often an analysis of a functions prologue.
+
+In order to extend testing coverage of the second level stack
+unwinding mechanisms it is helpful to be able to disable the DWARF
+stack unwinders, this can be done with this switch.
+
+In normal use of @value{GDBN} disabling the DWARF unwinders is not
+advisable, there are cases that are better handled through DWARF than
+prologue analysis, and the debug experience is likely to be better
+with the DWARF frame unwinders enabled.
+
+If DWARF frame unwinders are not supported for a particular target
+architecture, then enabling this flag does not cause them to be used.
 @kindex maint set profile
 @kindex maint show profile
 @cindex profiling GDB
diff --git a/gdb/dwarf2-frame-tailcall.c b/gdb/dwarf2-frame-tailcall.c
index 1d3e1f445bb..f565a2eecc8 100644
--- a/gdb/dwarf2-frame-tailcall.c
+++ b/gdb/dwarf2-frame-tailcall.c
@@ -318,6 +318,9 @@  tailcall_frame_sniffer (const struct frame_unwind *self,
   int next_levels;
   struct tailcall_cache *cache;
 
+  if (!dwarf2_frame_unwinders_enabled_p)
+    return 0;
+
   /* Inner tail call element does not make sense for a sentinel frame.  */
   next_frame = get_next_frame (this_frame);
   if (next_frame == NULL)
diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
index 91e16cf024e..fdd41b360e6 100644
--- a/gdb/dwarf2-frame.c
+++ b/gdb/dwarf2-frame.c
@@ -169,6 +169,9 @@  static CORE_ADDR read_encoded_value (struct comp_unit *unit, gdb_byte encoding,
 				     CORE_ADDR func_base);
 
 
+/* See dwarf2-frame.h.  */
+int dwarf2_frame_unwinders_enabled_p = 0;
+
 /* Store the length the expression for the CFA in the `cfa_reg' field,
    which is unused in that case.  */
 #define cfa_exp_len cfa_reg
@@ -1326,6 +1329,9 @@  static int
 dwarf2_frame_sniffer (const struct frame_unwind *self,
 		      struct frame_info *this_frame, void **this_cache)
 {
+  if (!dwarf2_frame_unwinders_enabled_p)
+    return 0;
+
   /* Grab an address that is guarenteed to reside somewhere within the
      function.  get_frame_pc(), with a no-return next function, can
      end up returning something past the end of this function's body.
@@ -1389,6 +1395,9 @@  dwarf2_append_unwinders (struct gdbarch *gdbarch)
 
   frame_unwind_append_unwinder (gdbarch, &dwarf2_frame_unwind);
   frame_unwind_append_unwinder (gdbarch, &dwarf2_signal_frame_unwind);
+
+  /* Mark dwarf frame unwinders as enabled.  */
+  dwarf2_frame_unwinders_enabled_p = 1;
 }
 
 
diff --git a/gdb/dwarf2-frame.h b/gdb/dwarf2-frame.h
index 471281a2c3f..56c90be8ceb 100644
--- a/gdb/dwarf2-frame.h
+++ b/gdb/dwarf2-frame.h
@@ -210,6 +210,12 @@  struct dwarf2_frame_state
   bool armcc_cfa_offsets_reversed = false;
 };
 
+/* When this is true the dwarf frame unwinders can be used if they are
+   registered with the gdbarch.  Not all architectures can or do use the
+   dwarf unwinders.  Setting this to true on a target that does not
+   otherwise support the dwarf unwinders has no effect.  */
+extern int dwarf2_frame_unwinders_enabled_p;
+
 /* Set the architecture-specific register state initialization
    function for GDBARCH to INIT_REG.  */
 
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 372f45ee175..b49d4d9fbbc 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -90,6 +90,7 @@ 
 #include <forward_list>
 #include "rust-lang.h"
 #include "common/pathstuff.h"
+#include "dwarf2-frame.h"
 
 /* When == 1, print basic high level tracing messages.
    When > 1, be more verbose.
@@ -1423,6 +1424,19 @@  show_dwarf_max_cache_age (struct ui_file *file, int from_tty,
 			    "DWARF compilation units is %s.\n"),
 		    value);
 }
+
+/* Handle 'maintenance show dwarf unwinders'.  */
+
+static void
+show_dwarf_unwinders_enabled_p (struct ui_file *file, int from_tty,
+				struct cmd_list_element *c,
+				const char *value)
+{
+  fprintf_filtered (file,
+		    _("The DWARF stack unwinders are currently %s.\n"),
+		    value);
+}
+
 
 /* local function prototypes */
 
@@ -25363,6 +25377,18 @@  conversational style, when possible."),
 			   &set_dwarf_cmdlist,
 			   &show_dwarf_cmdlist);
 
+  add_setshow_boolean_cmd ("unwinders", class_obscure,
+			   &dwarf2_frame_unwinders_enabled_p , _("\
+Set whether the DWARF stack frame unwinders are used."), _("\
+Show whether the DWARF stack frame unwinders are used."), _("\
+When enabled the DWARF stack frame unwinders can be used for architectures\n\
+that support the DWARF unwinders.  Enabling the dwarf unwinders for an\n\
+architecture that doesn't support them will have no effect."),
+			   NULL,
+			   show_dwarf_unwinders_enabled_p,
+			   &set_dwarf_cmdlist,
+			   &show_dwarf_cmdlist);
+
   add_setshow_zuinteger_cmd ("dwarf-read", no_class, &dwarf_read_debug, _("\
 Set debugging of the DWARF reader."), _("\
 Show debugging of the DWARF reader."), _("\
diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp
index 92086eec862..6125b6ec6f2 100644
--- a/gdb/testsuite/gdb.base/maint.exp
+++ b/gdb/testsuite/gdb.base/maint.exp
@@ -526,6 +526,10 @@  gdb_test_no_output "maint info line-table xxx.c" \
 
 set timeout $oldtimeout
 
+# Just check that the DWARF unwinders control flag is visible.
+gdb_test "maint show dwarf unwinders" \
+    "The DWARF stack unwinders are currently (on\|off)\."
+
 #============test help on maint commands
 
 test_prefix_command_help {"maint info" "maintenance info"} {