You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "anchao (via GitHub)" <gi...@apache.org> on 2023/05/24 01:54:16 UTC
[GitHub] [nuttx] anchao commented on a diff in pull request #9366: elf/coredump: add support of dump task stack without memory segments
anchao commented on code in PR #9366:
URL: https://github.com/apache/nuttx/pull/9366#discussion_r1203294230
##########
binfmt/libelf/libelf_coredump.c:
##########
@@ -161,143 +172,332 @@ static int elf_emit_header(FAR struct elf_dumpinfo_s *cinfo,
}
/****************************************************************************
- * Name: elf_get_note_size
+ * Name: elf_get_ntcb
*
* Description:
* Calculate the note segment size
*
****************************************************************************/
-static int elf_get_note_size(void)
+static int elf_get_ntcb(void)
{
int count = 0;
- int total;
int i;
for (i = 0; i < g_npidhash; i++)
{
- if (g_pidhash[i])
+ if (g_pidhash[i] != NULL)
{
count++;
}
}
- total = count * (sizeof(Elf_Nhdr) + ROUNDUP(CONFIG_TASK_NAME_SIZE, 8) +
- sizeof(elf_prstatus_t));
- total += count * (sizeof(Elf_Nhdr) + ROUNDUP(CONFIG_TASK_NAME_SIZE, 8) +
- sizeof(elf_prpsinfo_t));
+ return count;
+}
+
+/****************************************************************************
+ * Name: elf_get_note_size
+ *
+ * Description:
+ * Calculate the note segment size
+ *
+ ****************************************************************************/
+
+static int elf_get_note_size(int stksegs)
+{
+ int total;
+
+ total = stksegs * (sizeof(Elf_Nhdr) + ROUNDUP(CONFIG_TASK_NAME_SIZE, 8) +
+ sizeof(elf_prstatus_t));
+ total += stksegs * (sizeof(Elf_Nhdr) + ROUNDUP(CONFIG_TASK_NAME_SIZE, 8) +
+ sizeof(elf_prpsinfo_t));
return total;
}
/****************************************************************************
- * Name: elf_emit_note_info
+ * Name: elf_emit_tcb_note
*
* Description:
- * Fill the note segment information
+ * Fill the note segment information from tcb
*
****************************************************************************/
-static void elf_emit_note_info(FAR struct elf_dumpinfo_s *cinfo)
+static void elf_emit_tcb_note(FAR struct elf_dumpinfo_s *cinfo,
+ FAR struct tcb_s *tcb)
{
char name[ROUNDUP(CONFIG_TASK_NAME_SIZE, 8)];
- FAR struct tcb_s *tcb;
elf_prstatus_t status;
elf_prpsinfo_t info;
+ FAR uint32_t *regs;
Elf_Nhdr nhdr;
int i;
- int j;
memset(&info, 0x0, sizeof(info));
memset(&status, 0x0, sizeof(status));
- for (i = 0; i < g_npidhash; i++)
+ /* Fill Process info */
+
+ nhdr.n_namesz = sizeof(name);
+ nhdr.n_descsz = sizeof(info);
+ nhdr.n_type = NT_PRPSINFO;
+
+ elf_emit(cinfo, &nhdr, sizeof(nhdr));
+
+ strlcpy(name, tcb->name, sizeof(name));
+ elf_emit(cinfo, name, sizeof(name));
+
+ info.pr_pid = tcb->pid;
+ strlcpy(info.pr_fname, tcb->name, sizeof(info.pr_fname));
+ elf_emit(cinfo, &info, sizeof(info));
+
+ /* Fill Process status */
+
+ nhdr.n_descsz = sizeof(status);
+ nhdr.n_type = NT_PRSTATUS;
+
+ elf_emit(cinfo, &nhdr, sizeof(nhdr));
+ elf_emit(cinfo, name, sizeof(name));
+
+ status.pr_pid = tcb->pid;
+
+ if (running_task() == tcb)
+ {
+ if (up_interrupt_context())
+ {
+ regs = (FAR uint32_t *)CURRENT_REGS;
+ }
+ else
+ {
+ up_saveusercontext(g_running_regs);
+ regs = (FAR uint32_t *)g_running_regs;
+ }
+ }
+ else
+ {
+ regs = tcb->xcp.regs;
+ }
+
+ for (i = 0; i < nitems(status.pr_regs); i++)
{
- if (g_pidhash[i] == NULL)
+ if (regs == NULL)
+ {
+ memset(status.pr_regs, 0, sizeof(status.pr_regs));
+ break;
+ }
+
+ if (g_tcbinfo.reg_off.p[i] == UINT16_MAX)
{
continue;
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org