kexec.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Song Shuai <songshuaishuai@tinylab.org>
To: xianting.tian@linux.alibaba.com, k-hagio-ab@nec.com,
	kexec@lists.infradead.org, crash-utility@redhat.com
Cc: Song Shuai <songshuaishuai@tinylab.org>
Subject: [PATCH 1/2] [Crash-utility] RISCV64: Dump NT_PRSTATUS in 'help -n'
Date: Mon,  4 Dec 2023 18:50:14 +0800	[thread overview]
Message-ID: <20231204105015.2341055-1-songshuaishuai@tinylab.org> (raw)

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: 0  ppid: 0  pgrp: 0  sid:0
                         utime: 0.000000  stime: 0.000000
                         cutime: 0.000000  cstime: 0.000000
                         epc: ffffffff80822426   ra: ffffffff80822422 sp: ff20000000093f20
                          gp: ffffffff814ee2a8   tp: ff60000000104800 t0: ff2000000027bb18
                          t1: 0000000000000088   t2: 0000000000000000 s0: ff20000000093f30
                          s1: 0000000000000001   a0: 0000000000000004 a1: 0000000000000008
                          a2: ff6000009e9f0000   a3: 0000000000005fe4 a4: ffffffff80c1c290
                          a5: 0000000000000000   a6: ff6000001f60a6b0 a7: 00000088e4450548
                          s2: ffffffff814ef220   s3: 0000000000000002 s4: 000000000000003f
                          s8: ffffffff814ef3d8   s9: 0000000000000000 s10: ffffffff814ef0d0
                         s11: ffffffff81525d10   t3: ffffffff80c1d840 t4: 0000000000000000
                          t5: 0000000000000001   t6: 00000000000000aa
                         0000000000000000 0000000000000000
                         0000000000000000 0000000000000000
                         0000000000000000 0000000000000000
                         0000000000000000 0000000000000000
                         0000000000000000 0000000000000000
                         0000000000000000 0000000000000000
                         0000000000000000 0000000000000000
                         ffffffff80822426 ffffffff80822422
                         ff20000000093f20 ffffffff814ee2a8
                         ff60000000104800 ff2000000027bb18
<snip>
```

Signed-off-by: Song Shuai <songshuaishuai@tinylab.org>
---
 netdump.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)

diff --git a/netdump.c b/netdump.c
index 3907863..b266b27 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,79 @@ 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 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 +3524,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


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

             reply	other threads:[~2023-12-04 10:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-04 10:50 Song Shuai [this message]
2023-12-04 10:50 ` [PATCH 2/2] [Crash-utility] RISCV64: Fix 'bt' output when no ra on the stack top Song Shuai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231204105015.2341055-1-songshuaishuai@tinylab.org \
    --to=songshuaishuai@tinylab.org \
    --cc=crash-utility@redhat.com \
    --cc=k-hagio-ab@nec.com \
    --cc=kexec@lists.infradead.org \
    --cc=xianting.tian@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).