Skip to content

Commit

Permalink
command: Convert format-string in heapinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
koendv committed Nov 14, 2023
1 parent a9697dd commit b9e5f52
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*
/*
* This file implements a basic command interpreter for GDB 'monitor' commands.
*/

Expand Down Expand Up @@ -112,7 +112,7 @@ const command_s cmd_list[] = {
{"traceswo", cmd_traceswo, "Start trace capture, Manchester mode: [decode [CHANNEL_NR ...]]"},
#endif
#endif
{"heapinfo", cmd_heapinfo, "Set semihosting heapinfo: HEAPINFO HEAP_BASE HEAP_LIMIT STACK_BASE STACK_LIMIT"},
{"heapinfo", cmd_heapinfo, "Set semihosting heapinfo: HEAP_BASE HEAP_LIMIT STACK_BASE STACK_LIMIT"},
#if defined(PLATFORM_HAS_DEBUG) && PC_HOSTED == 0
{"debug_bmp", cmd_debug_bmp, "Output BMP \"debug\" strings to the second vcom: [enable|disable]"},
#endif
Expand Down Expand Up @@ -670,6 +670,14 @@ static bool cmd_shutdown_bmda(target_s *t, int argc, const char **argv)
}
#endif

/*
heapinfo can be used to quickly test a system with different heap and stack values, to see how much heap and stack is needed.
- user sets up values for heap and stack using "mon heapinfo"
- when the target boots, crt0.S does a heapinfo semihosting call to get these values for heap and stack.
See newlib/libc/sys/arm/crt0.S "Issue Angel SWI to read stack info"
- if the system crashes increase heap or stack
*/

static bool cmd_heapinfo(target_s *t, int argc, const char **argv)
{
if (t == NULL)
Expand All @@ -679,10 +687,11 @@ static bool cmd_heapinfo(target_s *t, int argc, const char **argv)
target_addr_t heap_limit = strtoul(argv[2], NULL, 16);
target_addr_t stack_base = strtoul(argv[3], NULL, 16);
target_addr_t stack_limit = strtoul(argv[4], NULL, 16);
gdb_outf("heapinfo heap_base: %p heap_limit: %p stack_base: %p stack_limit: %p\n", heap_base, heap_limit,
stack_base, stack_limit);
gdb_outf("heap_base: %08" PRIx32 " heap_limit: %08" PRIx32 " stack_base: %08" PRIx32 " stack_limit: %08" PRIx32
"\n",
heap_base, heap_limit, stack_base, stack_limit);
target_set_heapinfo(t, heap_base, heap_limit, stack_base, stack_limit);
} else
gdb_outf("heapinfo heap_base heap_limit stack_base stack_limit\n");
gdb_outf("?\n");
return true;
}

0 comments on commit b9e5f52

Please sign in to comment.