Skip to content

Commit

Permalink
coredump:Add a coreudmp api to watch custom variables
Browse files Browse the repository at this point in the history
VELAPLATFO-36377

Change-Id: I863ce2a43f3edf18a95b2c47447c5e66603afa85
Signed-off-by: anjiahao <[email protected]>
  • Loading branch information
anjiahao1 committed Sep 30, 2024
1 parent 7a5aa84 commit fbdbecf
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/nuttx/coredump.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@

int coredump_set_memory_region(FAR const struct memory_region_s *region);

/****************************************************************************
* Name: coredump_add_memory_region
*
* Description:
* Use coredump to dump the memory of the specified area.
*
****************************************************************************/

int coredump_add_memory_region(FAR const void *ptr, size_t size);

/****************************************************************************
* Name: coredump_initialize
*
Expand Down
75 changes: 75 additions & 0 deletions sched/misc/coredump.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,81 @@ int coredump_set_memory_region(FAR const struct memory_region_s *region)
return 0;
}

/****************************************************************************
* Name: coredump_add_memory_region
*
* Description:
* Use coredump to dump the memory of the specified area.
*
****************************************************************************/

int coredump_add_memory_region(FAR const void *ptr, size_t size)
{
FAR struct memory_region_s *region;
size_t count = 1; /* 1 for end flag */

if (g_regions != NULL)
{
region = (FAR struct memory_region_s *)g_regions;

while (region->start != 0)
{
if ((uintptr_t)ptr >= region->start &&
(uintptr_t)ptr + size < region->end)
{
/* Already watched */

return 0;
}
else if ((uintptr_t)ptr < region->end &&
(uintptr_t)ptr + size >= region->end)
{
/* start in region, end out of region */

region->end = (uintptr_t)ptr + size;
return 0;
}
else if ((uintptr_t)ptr < region->start &&
(uintptr_t)ptr + size >= region->start)
{
/* start out of region, end in region */

region->start = (uintptr_t)ptr;
return 0;
}
else if ((uintptr_t)ptr < region->start &&
(uintptr_t)ptr + size >= region->end)
{
/* start out of region, end out of region */

region->start = (uintptr_t)ptr;
region->end = (uintptr_t)ptr + size;
return 0;
}

count++;
region++;
}

/* Need a new region */
}

region = lib_realloc((FAR void *)g_regions,
sizeof(struct memory_region_s) * (count + 1));
if (region == NULL)
{
return -ENOMEM;
}

region[count - 1].start = (uintptr_t)ptr;
region[count - 1].end = (uintptr_t)ptr + size;
region[count - 1].flags = 0;
region[count].start = 0;

g_regions = region;
return 0;
}

/****************************************************************************
* Name: coredump_initialize
*
Expand Down

0 comments on commit fbdbecf

Please sign in to comment.