-
-
Notifications
You must be signed in to change notification settings - Fork 784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
command: Convert format-string in heapinfo #1681
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of relatively small (easily solved) issues we've spotted in review, but otherwise this looks good as a change. We'll be glad to get this merged once the review items have been addressed as amendments to the existing commit (not new commits).
src/command.c
Outdated
See newlib/libc/sys/arm/crt0.S "Issue Angel SWI to read stack info" | ||
- if the system crashes increase heap or stack | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please drop the extra new line so InteliSense and other tools see the comment as documentation for the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.
Every command has a one-line help message stored in cmd->help.
Maybe some bytes could be saved if a command, instead of printing a help message and exiting, could signal back: print the one-line help message for my command and exit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a usage message, but due to space constraints doesn't detail what the command is, it's purpose for existing, etc.. think you meant to reply to the above review item on the "?\n" change though.
Assuming we're right on that, it's something we've considered before but doing that well is going to be complicated - and not just because it changes so many commands across the code base, but because sometimes the message to be printed needs to be contextual. It's a good idea though to explore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of something like:
diff --git a/src/command.c b/src/command.c
index afae27be..d6fbc7ea 100644
--- a/src/command.c
+++ b/src/command.c
@@ -154,8 +154,14 @@ int command_process(target_s *const t, char *const cmd_buffer)
/* Accept a partial match as GDB does.
* So 'mon ver' will match 'monitor version'
*/
- if ((argc == 0) || !strncmp(argv[0], cmd->cmd, strlen(argv[0])))
- return !cmd->handler(t, argc, argv);
+ if ((argc == 0) || !strncmp(argv[0], cmd->cmd, strlen(argv[0]))) {
+ bool retval = cmd->handler(t, argc, argv);
+ if (retval == 2) {
+ gdb_out(cmd->help);
+ return 0;
+ }
+ return !retval;
+ }
}
if (!t)
so a command could do a return 2 to ask for the help message to be printed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could work for a simple version of the implementation - though the parens around the argc check need dropping and you'd need to use something other than bool
for retval
as bool
is not allowed to have an inspectable numerical value other than 0 and not-0 w/ not-0 being coerced to 1 when converted back to integer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea, but this will require changing the bool (*cmd_handler_fn)(target_s *target, int argc, const char **argv)
function-signature and consequently all the commands just so they can return 2. I'm more inclined towards using identical message strings. See PR1522 for an example of gcc/ld.bfd folding many identical constant string literals.
src/command.c
Outdated
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gdb_outf("heapinfo heap_base heap_limit stack_base stack_limit\n"); | |
gdb_outf("%s\n", "Set semihosting heapinfo: HEAP_BASE HEAP_LIMIT STACK_BASE STACK_LIMIT"); |
Such that we reuse the Usage/help message but still can stick a newline after it. Maybe even "Usage: %s\n"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such that we reuse the Usage/help message but still can stick a newline after it.
That's a good one. Maybe even pass the help string to the command?
--- a/src/command.c
+++ b/src/command.c
@@ -155,7 +155,7 @@ int command_process(target_s *const t, char *const cmd_buffer)
* So 'mon ver' will match 'monitor version'
*/
if ((argc == 0) || !strncmp(argv[0], cmd->cmd, strlen(argv[0])))
- return !cmd->handler(t, argc, argv);
+ return !cmd->handler(t, argc, argv, cmd->help);
}
if (!t)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current patch as it stands looks good to us - addressing all the review points. We're going to merge it as it stands to clear the way for #1676.
Further improvements to the command system to allow either the commands to take their help strings as a parameter, or for them to return if they want their usage displayed can be worked out in a separate PR that addresses the problem across all commands. Until a particular direction is agreed, may we suggest making an issue ticket for that so we can put all the conversation for it in one spot?
Detailed description
This PR
Your checklist for this pull request
make PROBE_HOST=native
)make PROBE_HOST=hosted
)Closing issues