You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/09/16 11:51:23 UTC
[nuttx] branch master updated (5bfda12634 -> 9f049b47bf)
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
from 5bfda12634 c++ compatibility: rename reserved c++ keywords 'public' and 'this'
new b52070a70e unwinder: fix unwind abort for uleb128 case
new 9f049b47bf backtrace/unwind: add more unwind instruction support
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
arch/arm/src/common/arm_backtrace_unwind.c | 83 +++++++++++++++++++++++++++++-
1 file changed, 82 insertions(+), 1 deletion(-)
[nuttx] 02/02: backtrace/unwind: add more unwind instruction support
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 9f049b47bfdda4f4246a0178e63e07147a5c5cbd
Author: chao an <an...@xiaomi.com>
AuthorDate: Thu Sep 14 16:42:05 2023 +0800
backtrace/unwind: add more unwind instruction support
Signed-off-by: chao an <an...@xiaomi.com>
---
arch/arm/src/common/arm_backtrace_unwind.c | 56 ++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/arch/arm/src/common/arm_backtrace_unwind.c b/arch/arm/src/common/arm_backtrace_unwind.c
index 599df384db..9369f91615 100644
--- a/arch/arm/src/common/arm_backtrace_unwind.c
+++ b/arch/arm/src/common/arm_backtrace_unwind.c
@@ -432,6 +432,62 @@ static int unwind_exec_content(struct unwind_ctrl_s *ctrl)
ctrl->vrs[SP] += 0x204 + (uleb128 << 2);
}
+ else if (content == 0xb3 || content == 0xc8 || content == 0xc9)
+ {
+ unsigned long reg_from;
+ unsigned long reg_to;
+ unsigned long mask;
+ unsigned long *vsp = (unsigned long *)ctrl->vrs[SP];
+ int i;
+
+ mask = unwind_get_byte(ctrl);
+ if (mask == 0)
+ {
+ return -1;
+ }
+
+ reg_from = (mask & 0xf0) >> 4;
+ reg_to = reg_from + (mask & 0x0f);
+
+ if (content == 0xc8)
+ {
+ reg_from += 16;
+ reg_to += 16;
+ }
+
+ for (i = reg_from; i <= reg_to; i++)
+ {
+ vsp += 2;
+ }
+
+ if (content == 0xb3)
+ {
+ vsp++;
+ }
+
+ ctrl->vrs[SP] = (unsigned long)vsp;
+ }
+ else if ((content & 0xf8) == 0xb8 || (content & 0xf8) == 0xd0)
+ {
+ unsigned long reg_to;
+ unsigned long mask = content & 0x07;
+ unsigned long *vsp = (unsigned long *)ctrl->vrs[SP];
+ int i;
+
+ reg_to = 8 + mask;
+
+ for (i = 8; i <= reg_to; i++)
+ {
+ vsp += 2;
+ }
+
+ if ((content & 0xf8) == 0xb8)
+ {
+ vsp++;
+ }
+
+ ctrl->vrs[SP] = (unsigned long)vsp;
+ }
else
{
ret = -1;
[nuttx] 01/02: unwinder: fix unwind abort for uleb128 case
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit b52070a70ec71db9d3fd6fcc8df4310f881e6663
Author: chao an <an...@xiaomi.com>
AuthorDate: Thu Sep 14 16:37:06 2023 +0800
unwinder: fix unwind abort for uleb128 case
When unwind instruction is 0xb2,the subsequent instructions
are uleb128 bytes.
For now,it uses only the first uleb128 byte in code.
For vsp increments of 0x204~0x400,use one uleb128 byte like below:
0xc06a00e4 <unwind_test_work>: 0x80b27fac
Compact model index: 0
0xb2 0x7f vsp = vsp + 1024
0xac pop {r4, r5, r6, r7, r8, r14}
For vsp increments larger than 0x400,use two uleb128 bytes like below:
0xc06a00e4 <unwind_test_work>: @0xc0cc9e0c
Compact model index: 1
0xb2 0x81 0x01 vsp = vsp + 1032
0xac pop {r4, r5, r6, r7, r8, r14}
The unwind works well since the decoded uleb128 byte is also 0x81.
For vsp increments larger than 0x600,use two uleb128 bytes like below:
0xc06a00e4 <unwind_test_work>: @0xc0cc9e0c
Compact model index: 1
0xb2 0x81 0x02 vsp = vsp + 1544
0xac pop {r4, r5, r6, r7, r8, r14}
In this case,the decoded uleb128 result is 0x101(vsp=0x204+(0x101<<2)).
While the uleb128 used in code is 0x81(vsp=0x204+(0x81<<2)).
The unwind aborts at this frame since it gets incorrect vsp.
To fix this, add uleb128 decode to cover all the above case.
Signed-off-by: chao an <an...@xiaomi.com>
---
arch/arm/src/common/arm_backtrace_unwind.c | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/arch/arm/src/common/arm_backtrace_unwind.c b/arch/arm/src/common/arm_backtrace_unwind.c
index 0a96b59a55..599df384db 100644
--- a/arch/arm/src/common/arm_backtrace_unwind.c
+++ b/arch/arm/src/common/arm_backtrace_unwind.c
@@ -338,6 +338,31 @@ static int unwind_exec_pop_subset_r0_to_r3(struct unwind_ctrl_s *ctrl,
return 0;
}
+static unsigned long unwind_decode_uleb128(struct unwind_ctrl_s *ctrl)
+{
+ unsigned long bytes = 0;
+ unsigned long insn;
+ unsigned long result = 0;
+
+ /* unwind_get_byte() will advance `ctrl` one instruction at a time, so
+ * loop until we get an instruction byte where bit 7 is not set.
+ *
+ * Note: This decodes a maximum of 4 bytes to output 28 bits data where
+ * max is 0xfffffff: that will cover a vsp increment of 1073742336, hence
+ * it is sufficient for unwinding the stack.
+ */
+
+ do
+ {
+ insn = unwind_get_byte(ctrl);
+ result |= (insn & 0x7f) << (bytes * 7);
+ bytes++;
+ }
+ while (!!(insn & 0x80) && (bytes != sizeof(result)));
+
+ return result;
+}
+
/****************************************************************************
* Name: unwind_pop_register
*
@@ -403,7 +428,7 @@ static int unwind_exec_content(struct unwind_ctrl_s *ctrl)
}
else if (content == 0xb2)
{
- unsigned long uleb128 = unwind_get_byte(ctrl);
+ unsigned long uleb128 = unwind_decode_uleb128(ctrl);
ctrl->vrs[SP] += 0x204 + (uleb128 << 2);
}