|
Message-ID: <CAAvnz_rJHonjja=_7mAA8B66uSk3QeeUFdSM86cHVumiE=Hotw@mail.gmail.com>
Date: Fri, 19 Jul 2024 17:06:19 +0800
From: Howard Su <howard0su@...il.com>
To: musl@...ts.openwall.com
Subject: [Suggestion] Add cfi directives to assembly code via chatgpt
I am working on a project on Alpine OS on ARM. I have hard time to debug a
multi thread application. GDB cannot generate full backtrace.
(gdb) bt
#0 __cp_begin () at src/thread/arm/syscall_cp.s:23
#1 0xb6f1f532 in __syscall_cp_c (nr=7639428, u=<optimized out>,
v=<optimized out>, w=0, x=0, y=-1093370608, z=2)
at src/thread/pthread_cancel.c:33
#2 0xbed47cc0 in ?? ()
I am suggesting that we can add CFI to assembly code to make sure it
generates the symbols to support gdb.
I tried ChatGPT which is able to write cfi directives correctly. Pick the
above thread cancellation point as example. Not perfect but only little
changes needed.
.global __syscall_cp_asm
.type __syscall_cp_asm,%function
__syscall_cp_asm:
.cfi_startproc
mov ip,sp
.cfi_def_cfa_register ip
stmfd sp!,{r4,r5,r6,r7,lr}
.cfi_adjust_cfa_offset 20
.cfi_rel_offset r4, 0
.cfi_rel_offset r5, 4
.cfi_rel_offset r6, 8
.cfi_rel_offset r7, 12
.cfi_rel_offset lr, 16
.global __cp_begin
__cp_begin:
ldr r0,[r0]
cmp r0,#0
blne __cancel
mov r7,r1
mov r0,r2
mov r1,r3
ldmfd ip,{r2,r3,r4,r5,r6}
.cfi_remember_state
.cfi_def_cfa ip, 0
svc 0
.global __cp_end
__cp_end:
.cfi_restore_state
ldmfd sp!,{r4,r5,r6,r7,lr}
.cfi_adjust_cfa_offset -20
.cfi_restore r4
.cfi_restore r5
.cfi_restore r6
.cfi_restore r7
.cfi_restore lr
tst lr,#1
moveq pc,lr
.cfi_return_column lr
bx lr
.cfi_endproc
--
-Howard
Content of type "text/html" skipped
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.