On Fri, May 31, 2024 at 5:38 PM <devel-request@lists.crash-utility.osci.io> wrote:
Date: Fri, 31 May 2024 17:19:35 +0800
From: Tao Liu <ltao@redhat.com>
Subject: [Crash-utility] [PATCH v4 12/16] x86_64: Fix invalid input
        "=>" for bt command
To: devel@lists.crash-utility.osci.io
Cc: Mahesh J Salgaonkar <mahesh@linux.ibm.com>, "Naveen N . Rao"
        <naveen.n.rao@linux.vnet.ibm.com>, Lianbo Jiang <lijiang@redhat.com>,
        Alexey Makhalov <alexey.makhalov@broadcom.com>
Message-ID: <20240531091939.97828-13-ltao@redhat.com>
Content-Type: text/plain; charset=UTF-8

There may be extra "=>" prefix before gdb disassembly, as a result,
parse_line() will return string "=>" as arglist[0], which will be
converted to number by htol() and fails. E.g.:

crash> gdb x/40i __list_del_entry
   ...
   0xffffffff8133c384 <__list_del_entry+36>:    cmp    %rcx,%rax
   0xffffffff8133c387 <__list_del_entry+39>:    je     0xffffffff8133c403 <__list_del_entry+163>
=> 0xffffffff8133c389 <__list_del_entry+41>:    mov    (%rax),%r8
   0xffffffff8133c38c <__list_del_entry+44>:    cmp    %r8,%rdi
   0xffffffff8133c38f <__list_del_entry+47>:    jne    0xffffffff8133c3e4 <__list_del_entry+132>
   0xffffffff8133c391 <__list_del_entry+49>:    mov    0x8(%rdx),%r8

Before the patch:

crash> bt
 ...
 #10 [ffff880095647c00] async_page_fault at ffffffff816a8638
    [exception RIP: __list_del_entry+41]
    RIP: ffffffff8133c389  RSP: ffff880095647cb0  RFLAGS: 00010207
    RAX: 0000000000000000  RBX: ffffea0400408020  RCX: dead000000000200
    RDX: 0000000000000000  RSI: 0000000000000246  RDI: ffffea0400408020
    RBP: ffff880095647cb0   R8: 0000000080000431   R9: ffffffff81e835c0
    R10: 0000000000000000  R11: 0000000000000400  R12: ffff880138795b58
    R13: 0000000010010201  R14: ffff880095647d70  R15: 0000000400408040
    ORIG_RAX: ffffffffffffffff  CS: 0010  SS: 0018
 bt: invalid input: "=>"
 #11 [ffff880095647cb8] list_del at ffffffff8133c43d
 #12 [ffff880095647cd0] devm_memremap_pages at ffffffff81180c53

After the patch:

No string as 'bt: invalid input: "=>"' of output.

Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Mahesh J Salgaonkar <mahesh@linux.ibm.com>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Lianbo Jiang <lijiang@redhat.com>
Cc: HAGIO KAZUHITO(萩尾 一仁) <k-hagio-ab@nec.com>
Cc: Tao Liu <ltao@redhat.com>
Cc: Alexey Makhalov <alexey.makhalov@broadcom.com>
Signed-off-by: Tao Liu <ltao@redhat.com>
---
 x86_64.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/x86_64.c b/x86_64.c
index 54c69fd..47c215f 100644
--- a/x86_64.c
+++ b/x86_64.c
@@ -8829,6 +8829,8 @@ x86_64_get_framesize(struct bt_info *bt, ulong textaddr, ulong rsp, char *stack_

         rewind(pc->tmpfile2);
         while (fgets(buf, BUFSIZE, pc->tmpfile2)) {
+               if (STRNEQ(buf, "=>"))
+                       shift_string_left(buf, 2);
                strcpy(buf2, buf);


This looks good.

Thanks
Lianbo
 
                if (CRASHDEBUG(3))
--
2.40.1