Re: [PATCH 2/3] LoongArch: Add prologue unwinder support

From: zhangqing
Date: Fri Jul 29 2022 - 01:39:00 EST




On 2022/7/29 上午10:03, Youling Tang wrote:


On 07/28/2022 10:05 PM, Qing Zhang wrote:
It unwind the stack frame based on prologue code analyze.
CONFIG_KALLSYMS is needed, at least the address and length
of each function.

Three stages when we do unwind,
  (1)unwind_start(), the prapare of unwinding, fill unwind_state.
  (2)unwind_done(), judge whether the unwind process is finished or not.
  (3)unwind_next_frame(), unwind the next frame.

Dividing unwinder helps to add new unwinders in the future, eg:
unwind_frame, unwind_orc .etc

Signed-off-by: Qing Zhang <zhangqing@xxxxxxxxxxx>

+
+    while (ip < ip_end) {
+        if (is_ra_save_ins(ip)) {
+            frame_ra = ip->reg2i12_format.immediate;
Because the immediate member in struct reg2i12_format is defined as an
unsigned type, the value obtained by frame_ra here can only be a
positive number.

+            break;
+        }
+        if (is_branch_insn(*ip))
+            break;
+        ip++;
+    }
+
+    if (frame_ra < 0) {
In addition to judging whether the initial value of frame_ra is
negative, we also want to judge whether the previously assigned
frame_ra is negative.

Save the ra value to the stack in the prologue, offset must be a
positive number, so we can add another judgment to is_ra_save_ins, the
code is as follows:
+static inline bool is_ra_save_ins(union loongarch_instruction *ip)
+{
+    /* st.d $ra, $sp, offset */
+    return ip->reg2i12_format.opcode == std_op &&
+        ip->reg2i12_format.rj == LOONGARCH_GPR_SP &&
+        ip->reg2i12_format.rd == LOONGARCH_GPR_RA &&
+        !(ip->reg2i12_format.immediate & (1 << 11));
+}

Hi,
youling

you are right and I will send v2.

Thanks,
Qing