Hi, Song

Thank you for the patch series.

On 12/13/23 09:57, [email protected] wrote:

Date: Tue, 12 Dec 2023 18:20:50 +0800
From: Song Shuai<[email protected]>
Subject: [Crash-utility] [PATCH V2 1/2] RISCV64: Dump NT_PRSTATUS in
        'help -n'
To:[email protected],[email protected]
Cc:[email protected], Song Shuai
        <[email protected]>
Message-ID:<[email protected]>

With the patch we can get full dump of "struct elf_prstatus" in 'help -n':

```
crash> help -n
<snip>
Elf64_Nhdr:
                n_namesz: 5 ("CORE")
                n_descsz: 376
                  n_type: 1 (NT_PRSTATUS)
                          si.signo: 0  si.code: 0  si.errno: 0
                          cursig: 0  sigpend: 0  sighold: 0
                          pid: 1  ppid: 0  pgrp: 0  sid:0
                          utime: 0.000000  stime: 0.000000
                          cutime: 0.000000  cstime: 0.000000
                          epc: ffffffff8000a1dc   ra: ffffffff800af958 sp: 
ff6000001fc501c0
                           gp: ffffffff81515d38   tp: ff600000000d8000 t0: 
6666666666663c5b
                           t1: ff600000000d88c8   t2: 666666666666663c s0: 
ff6000001fc50320
                           s1: ffffffff815170d8   a0: ff6000001fc501c8 a1: 
c0000000ffffefff
                           a2: 0000000000000000   a3: 0000000000000001 a4: 
0000000000000000
                           a5: ff60000001782c00   a6: 000000000130e0f0 a7: 
0000000000000000
                           s2: ffffffff81517820   s3: ff6000001fc501c8 s4: 
000000000000000f
                           s5: 0000000000000000   s6: ff20000000013e60 s7: 
0000000000000000
                           s8: ff60000000861000   s9: 00007fffc3641694 s10: 
00007fffc3641690
                          s11: 00005555796ed240   t3: 0000000000010297 t4: 
ffffffff80c17810
                           t5: ffffffff8195e7b8   t6: ff6000001fc50048
                          0000000000000000 0000000000000000
                          0000000000000000 0000000000000000
                          0000000000000001 0000000000000000
                          0000000000000000 0000000000000000
                          0000000000000000 0000000000000000
                          0000000000000000 0000000000000000
                          0000000000000000 0000000000000000
                          ffffffff8000a1dc ffffffff800af958
                          ff6000001fc501c0 ffffffff81515d38
                          ff600000000d8000 6666666666663c5b
<snip>
```

Signed-off-by: Song Shuai<[email protected]>
---
Changes since V1:
https://lore.kernel.org/kexec/[email protected]/
- patch1: add the missing "s5-s7" format string back
- patch2: add Acked-by from Kazuhito Hagio
- Resend to the new crash list address

I can not do the tests, seems the kexec-tools does not support the riscv64 arch yet:

[root@fedora-riscv kexec-tools]# ./configure
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking build system type... riscv64-unknown-linux-gnu
checking host system type... riscv64-unknown-linux-gnu
checking target system type... riscv64-unknown-linux-gnu
configure: error: unsupported architecture riscv64
[root@fedora-riscv kexec-tools]#


Anyway, the v2 looks good to me, so: Ack

BTW: I have a request: could you please provide a patched kexec-tools(link) for riscv64 arch? That could be useful for testing  patches.


Thanks

Lianbo


---
  netdump.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 84 insertions(+)

diff --git a/netdump.c b/netdump.c
index 3907863..32586b6 100644
--- a/netdump.c
+++ b/netdump.c
@@ -2578,6 +2578,8 @@ dump_Elf64_Nhdr(Elf64_Off offset, int store)
                                display_ELF_note(EM_PPC64, PRSTATUS_NOTE, note, 
nd->ofp);
                        if (machine_type("ARM64") && (note->n_type == 
NT_PRSTATUS))
                                display_ELF_note(EM_AARCH64, PRSTATUS_NOTE, note, 
nd->ofp);
+                       if (machine_type("RISCV64") && (note->n_type == 
NT_PRSTATUS))
+                               display_ELF_note(EM_RISCV, PRSTATUS_NOTE, note, 
nd->ofp);
                }
                for (i = lf = 0; i < note->n_descsz/sizeof(ulonglong); i++) {
                        if (((i%2)==0)) {
@@ -3399,6 +3401,80 @@ display_prstatus_arm64(void *note_ptr, FILE *ofp)
                space(sp), pr->pr_reg[33], pr->pr_fpvalid);
  }
+struct riscv64_elf_siginfo {
+    int si_signo;
+    int si_code;
+    int si_errno;
+};
+
+struct riscv64_elf_prstatus {
+    struct riscv64_elf_siginfo pr_info;
+    short pr_cursig;
+    unsigned long pr_sigpend;
+    unsigned long pr_sighold;
+    pid_t pr_pid;
+    pid_t pr_ppid;
+    pid_t pr_pgrp;
+    pid_t pr_sid;
+    struct timeval pr_utime;
+    struct timeval pr_stime;
+    struct timeval pr_cutime;
+    struct timeval pr_cstime;
+/*  elf_gregset_t pr_reg; => typedef struct user_regs_struct elf_gregset_t; */
+    unsigned long pr_reg[32];
+    int pr_fpvalid;
+};
+
+static void
+display_prstatus_riscv64(void *note_ptr, FILE *ofp)
+{
+       struct riscv64_elf_prstatus *pr;
+       Elf64_Nhdr *note;
+       int sp;
+
+       note = (Elf64_Nhdr *)note_ptr;
+       pr = (struct riscv64_elf_prstatus *)(
+               (char *)note + sizeof(Elf64_Nhdr) + note->n_namesz);
+       pr = (struct riscv64_elf_prstatus *)roundup((ulong)pr, 4);
+       sp = nd->num_prstatus_notes ? 25 : 22;
+
+       fprintf(ofp,
+               "%ssi.signo: %d  si.code: %d  si.errno: %d\n"
+               "%scursig: %d  sigpend: %lx  sighold: %lx\n"
+               "%spid: %d  ppid: %d  pgrp: %d  sid:%d\n"
+               "%sutime: %01lld.%06d  stime: %01lld.%06d\n"
+               "%scutime: %01lld.%06d  cstime: %01lld.%06d\n",
+               space(sp), pr->pr_info.si_signo, pr->pr_info.si_code, 
pr->pr_info.si_errno,
+               space(sp), pr->pr_cursig, pr->pr_sigpend, pr->pr_sighold,
+               space(sp), pr->pr_pid, pr->pr_ppid, pr->pr_pgrp, pr->pr_sid,
+               space(sp), (long long)pr->pr_utime.tv_sec, 
(int)pr->pr_utime.tv_usec,
+               (long long)pr->pr_stime.tv_sec, (int)pr->pr_stime.tv_usec,
+               space(sp), (long long)pr->pr_cutime.tv_sec, 
(int)pr->pr_cutime.tv_usec,
+               (long long)pr->pr_cstime.tv_sec, (int)pr->pr_cstime.tv_usec);
+       fprintf(ofp,
+               "%sepc: %016lx   ra: %016lx   sp: %016lx\n"
+               "%s gp: %016lx   tp: %016lx   t0: %016lx\n"
+               "%s t1: %016lx   t2: %016lx   s0: %016lx\n"
+               "%s s1: %016lx   a0: %016lx   a1: %016lx\n"
+               "%s a2: %016lx   a3: %016lx   a4: %016lx\n"
+               "%s a5: %016lx   a6: %016lx   a7: %016lx\n"
+               "%s s2: %016lx   s3: %016lx   s4: %016lx\n"
+               "%s s5: %016lx   s6: %016lx   s7: %016lx\n"
+               "%s s8: %016lx   s9: %016lx  s10: %016lx\n"
+               "%ss11: %016lx   t3: %016lx   t4: %016lx\n"
+               "%s t5: %016lx   t6: %016lx\n",
+               space(sp), pr->pr_reg[0], pr->pr_reg[1], pr->pr_reg[2],
+               space(sp), pr->pr_reg[3], pr->pr_reg[4], pr->pr_reg[5],
+               space(sp), pr->pr_reg[6], pr->pr_reg[7], pr->pr_reg[8],
+               space(sp), pr->pr_reg[9], pr->pr_reg[10], pr->pr_reg[11],
+               space(sp), pr->pr_reg[12], pr->pr_reg[13], pr->pr_reg[14],
+               space(sp), pr->pr_reg[15], pr->pr_reg[16], pr->pr_reg[17],
+               space(sp), pr->pr_reg[18], pr->pr_reg[19], pr->pr_reg[20],
+               space(sp), pr->pr_reg[21], pr->pr_reg[22], pr->pr_reg[23],
+               space(sp), pr->pr_reg[24], pr->pr_reg[25], pr->pr_reg[26],
+               space(sp), pr->pr_reg[27], pr->pr_reg[28], pr->pr_reg[29],
+               space(sp), pr->pr_reg[30], pr->pr_reg[31]);
+}
void
  display_ELF_note(int machine, int type, void *note, FILE *ofp)
@@ -3449,6 +3525,14 @@ display_ELF_note(int machine, int type, void *note, FILE 
*ofp)
                        break;
                }
                break;
+       case EM_RISCV:
+               switch (type)
+               {
+               case PRSTATUS_NOTE:
+                       display_prstatus_riscv64(note, ofp);
+                       break;
+               }
+               break;
default:
                return;
-- 2.20.1
--
Crash-utility mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://${domain_name}/admin/lists/devel.lists.crash-utility.osci.io/
Contribution Guidelines: https://github.com/crash-utility/crash/wiki

Reply via email to