public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "tomas.vanek at fbl dot cz" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug gdb/28549] ARM/Cortex-M: improper stack unwinding when the target is in lockup state
Date: Sun, 16 Oct 2022 12:24:57 +0000	[thread overview]
Message-ID: <bug-28549-4717-N59MztKRoD@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-28549-4717@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=28549

--- Comment #50 from tomas.vanek at fbl dot cz ---
I finally submitted
https://sourceware.org/pipermail/gdb-patches/2022-October/192716.html

(In reply to Torbjörn SVENSSON from comment #49)
> 
> Right now, I'm more concerned about the endless(?) loop when the target is
> in lockup state.

Could it be explained by unwinding with wrong SP value because the size
of the next outer frame cannot be determined because of unknown pre-lockup PC?

> > 'Show frame unwinder name in signal name' gives user little bit better info
> > than <signal handler called> - it might be mergeable (I didn't check, will
> > do).
> 
> I think this patch could be an improvement, but not as important as the
> previous one. Lets focus on getting the other one in first, okay?

Because you doesn't seem to be happy with
'Show frame unwinder name in signal name'...

> I just landed a patch that shows how you can use the 
> frame_unwind_stop_reason hook to stop the unwinding. I think the same logic
> could be used in your patch too.

... and your patch made much easier to stop unwinding without misleading
messages, I simplified the change. Dedicated lockup unwinder is dropped,
I added the equal functionality to the exception unwinder.

TBH Personally I would prefer 3 dedicated unwinders: exception (EXC_RETURN),
FNC_RETURN and lockup. I think that performance penalty would be negligible
as the sniffers are simple and fast and the code would be cleaner. However I'm
not so familiar with gdb code so I respect your preference.

BTW Thanks for the pointer to
> Regarding the assurance, please see Pedro's reply to the very same question
> here: https://sourceware.org/pipermail/gdb-patches/2022-October/192655.html

and submitting your
'[PATCH v4] gdb/arm: Stop unwinding on error, but do not assert'
and
'[PATCH] gdb/arm: Don't rely on loop detection to stop unwind'

They really make a difference.
But there is a small drawback: as the warning messages are printed out in time
of building cache, they appear just once and if user e.g. repeats 'backtrace'
command he gets no more messages.


> > I wonder why arm_m_addr_is_magic() decoding differs so much in branches
> > without and with the security extension. The former decodes just the used
> > special addresses, the latter whole pages with lot of 'undefined behaviour'
> > codes.
> 
> On
> https://developer.arm.com/documentation/100701/0200/The-EXC-RETURN-register,
> it's written as that 0xffxxxxxx is an EXC_RETURN pattern, even if there are
> combinations within that that is illegal.

Hmm, this document really looks like the devices without sec ext have just
3 listed EXC_RETURNs. 'Arm®v8-M Architecture Reference Manual', D1.2.95
'EXC_RETURN, Exception Return Payload' makes clear that the payload format and
bits assignment are same for both with and without sec ext, just some bits are
reserved in the case 'without sec'.
So IMO detecting EXC_RETURN on a device with security extension should treat
reserved bits same way as doing so on dev w/o sec, not to do the quite
opposite.

And one more suspicious point: ARMv8-M RM describes the FType bit 4
as it does not depend on sec ext. Correct me if I'm wrong it would mean
that ARMv8-M device with FP and without security used also 0xFFFFFFA0,
0xFFFFFFA8 and 0xFFFFFFAC EXC_RETURNs. I don't have such device
neither I'm not aware of any, it even does not exist at all.

BTW it's quite easy to trigger the internal error at the end of
arm_m_exception_cache(). Just set PC register to any of magic codes
(I admit that doing so has little sense except showing another reason to check
the reserved bits):

On STM32L5 ARMv8-M with sec ext:

(gdb) set $pc=0xff000000
../../gdb/arm-tdep.c:3684: internal-error: While unwinding an exception frame,
found unexpected Link Register value 0c0002cb.  This should not happen and
maybe caused by corrupt data or a bug in GDB.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
----- Backtrace -----
0x8119852 gdb_internal_backtrace_1
        ../../gdb/bt-utils.c:122
0x8119852 _Z22gdb_internal_backtracev
        ../../gdb/bt-utils.c:168
0x843a40c internal_vproblem
        ../../gdb/utils.c:396
0x843a79e _Z15internal_verrorPKciS0_Pc
        ../../gdb/utils.c:476
0x8528326 _Z14internal_errorPKciS0_z
        ../../gdbsupport/errors.cc:58
0x80cf181 arm_m_exception_cache
        ../../gdb/arm-tdep.c:3689
0x80cff77 arm_m_exception_this_id
        ../../gdb/arm-tdep.c:3703
0x8257bbe compute_frame_id
        ../../gdb/frame.c:594
0x8257e49 _Z12get_frame_id14frame_info_ptr
        ../../gdb/frame.c:637
0x825b185 _Z16frame_find_by_id8frame_id
        ../../gdb/frame.c:906
0x8447bbf _Z12value_assignP5valueS0_
        ../../gdb/valops.c:1304
0x8226a46 _ZN10expression8evaluateEP4type6noside
        ../../gdb/eval.c:101
0x8226e8e _Z19evaluate_expressionP10expressionP4type
        ../../gdb/eval.c:115
0x8328a4e set_command
        ../../gdb/printcmd.c:1519
0x814b1aa _Z8cmd_funcP16cmd_list_elementPKci
        ../../gdb/cli/cli-decode.c:2543
0x84001bb _Z15execute_commandPKci
        ../../gdb/top.c:692
0x822dff4 _Z15command_handlerPKc
        ../../gdb/event-top.c:616
0x822e366 _Z20command_line_handlerOSt10unique_ptrIcN3gdb13xfree_deleterIcEEE
        ../../gdb/event-top.c:860

On Kinetis K22, Cortex-M4 FP:

(gdb) set $pc=0xFFFFFFBC
the same error follows...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2022-10-16 12:24 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-05  9:51 [Bug gdb/28549] New: " tarek.bouchkati at gmail dot com
2021-11-05 10:34 ` [Bug gdb/28549] " tarek.bouchkati at gmail dot com
2021-11-05 10:59 ` tarek.bouchkati at gmail dot com
2021-11-05 12:26 ` tarek.bouchkati at gmail dot com
2021-11-05 12:36 ` tarek.bouchkati at gmail dot com
2021-11-05 13:16 ` alahay01 at gcc dot gnu.org
2021-11-05 13:22 ` luis.machado at linaro dot org
2021-11-05 14:02 ` luis.machado at linaro dot org
2021-11-05 14:02 ` luis.machado at linaro dot org
2021-11-05 15:43 ` fredrik.hederstierna@securitas-direct.com
2021-11-05 15:51 ` tarek.bouchkati at gmail dot com
2021-11-05 23:14 ` fredrik.hederstierna@securitas-direct.com
2021-11-05 23:25 ` fredrik.hederstierna@securitas-direct.com
2021-11-06  0:20 ` fredrik.hederstierna@securitas-direct.com
2021-11-15 12:04 ` tarek.bouchkati at gmail dot com
2021-11-15 12:52 ` luis.machado at linaro dot org
2021-11-15 13:15 ` tarek.bouchkati at gmail dot com
2021-11-15 18:09 ` fredrik.hederstierna@securitas-direct.com
2021-11-15 18:46 ` luis.machado at linaro dot org
2021-11-18 11:18 ` tarek.bouchkati at gmail dot com
2021-12-10 12:30 ` tomas.vanek at fbl dot cz
2021-12-13  8:30 ` luis.machado at linaro dot org
2021-12-13  9:55 ` tomas.vanek at fbl dot cz
2021-12-13 10:07 ` clyon at gcc dot gnu.org
2021-12-13 10:35 ` luis.machado at linaro dot org
2021-12-13 10:37 ` luis.machado at linaro dot org
2021-12-13 20:22 ` tomas.vanek at fbl dot cz
2021-12-13 21:48 ` fredrik.hederstierna@securitas-direct.com
2021-12-13 22:00 ` fredrik.hederstierna@securitas-direct.com
2021-12-14  0:09 ` tomas.vanek at fbl dot cz
2021-12-14  0:33 ` tomas.vanek at fbl dot cz
2021-12-14 10:27 ` tomas.vanek at fbl dot cz
2021-12-14 14:42 ` tomas.vanek at fbl dot cz
2021-12-14 14:45 ` tomas.vanek at fbl dot cz
2021-12-14 14:50 ` tomas.vanek at fbl dot cz
2021-12-15 16:44 ` luis.machado at linaro dot org
2021-12-15 16:56 ` fredrik.hederstierna@securitas-direct.com
2021-12-15 17:42 ` tomas.vanek at fbl dot cz
2022-01-19 11:34 ` tarek.bouchkati at gmail dot com
2022-01-19 11:35 ` luis.machado at linaro dot org
2022-01-19 11:36 ` luis.machado at linaro dot org
2022-01-19 11:40 ` clyon at gcc dot gnu.org
2022-01-19 12:18 ` tarekbouchkati at gmail dot com
2022-09-09  8:25 ` luis.machado at arm dot com
2022-09-09 23:35 ` fredrik.hederstierna@securitas-direct.com
2022-09-10  7:27 ` luis.machado at arm dot com
2022-09-11 13:59 ` tomas.vanek at fbl dot cz
2022-09-12  9:32 ` luis.machado at arm dot com
2022-09-14  9:07 ` tomas.vanek at fbl dot cz
2022-09-14 12:10 ` luis.machado at arm dot com
2022-10-02  7:13 ` torbjorn.svensson at st dot com
2022-10-02  7:18 ` tomas.vanek at fbl dot cz
2022-10-06 13:07 ` luis.machado at arm dot com
2022-10-11  8:08 ` torbjorn.svensson at st dot com
2022-10-14 14:07 ` torbjorn.svensson at st dot com
2022-10-16 12:24 ` tomas.vanek at fbl dot cz [this message]
2022-10-21 10:01 ` luis.machado at arm dot com
2022-10-29 18:40 ` brobecker at gnat dot com
2022-10-31 10:18 ` luis.machado at arm dot com

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=bug-28549-4717-N59MztKRoD@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).