]> git.sur5r.net Git - openocd/commitdiff
arm: semihosting: set command line arguments
authorAndreas Fritiofson <andreas.fritiofson@gmail.com>
Wed, 28 Dec 2016 22:43:53 +0000 (23:43 +0100)
committerAndreas Fritiofson <andreas.fritiofson@gmail.com>
Sun, 22 Oct 2017 22:06:09 +0000 (23:06 +0100)
Add "arm semihosting_cmdline [argv0 argv1 ...]" for setting the
command line arguments for the debuggee.

[andreas.fritiofson@gmail.com]: Dynamic allocation, empty default

Change-Id: I831ddd161d602f251940e29608a154e9590fdee1
Signed-off-by: Christian Groessler <chris@groessler.org>
Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-on: http://openocd.zylin.com/3106
Tested-by: jenkins
doc/openocd.texi
src/target/arm.h
src/target/arm_semihosting.c
src/target/armv4_5.c

index 39b81ea85161612bce316241742a1447b5236678..e452fa3b3ad9d78a67d41fa24fba86a76d251416 100644 (file)
@@ -7604,6 +7604,20 @@ requests by using a special SVC instruction that is trapped at the
 Supervisor Call vector by OpenOCD.
 @end deffn
 
+@deffn Command {arm semihosting_cmdline} [@option{enable}|@option{disable}]
+@cindex ARM semihosting
+Set the command line to be passed to the debuggee.
+
+@example
+arm semihosting_cmdline argv0 argv1 argv2 ...
+@end example
+
+This option lets one set the command line arguments to be passed to
+the program. The first argument (argv0) is the program name in a
+standard C environment (argv[0]). Depending on the program (not much
+programs look at argv[0]), argv0 is ignored and can be any string.
+@end deffn
+
 @deffn Command {arm semihosting_fileio} [@option{enable}|@option{disable}]
 @cindex ARM semihosting
 Display status of semihosting fileio, after optionally changing that
index d63ead215159d5e430d0a6de75b2e0e5a44c8275..f89aa68846e4e595a4eebe33df6d14825e096fa8 100644 (file)
@@ -157,6 +157,9 @@ struct arm {
 
        int (*setup_semihosting)(struct target *target, int enable);
 
+       /** Semihosting command line. */
+       char *semihosting_cmdline;
+
        /** Backpointer to the target. */
        struct target *target;
 
index 252511962da1bdbda1fe1430ad0dd6bc0df4bb84..f31f901f0b7bd328e19f7319f796aab2645d1780 100644 (file)
@@ -465,7 +465,7 @@ static int do_semihosting(struct target *target)
                else {
                        uint32_t a = target_buffer_get_u32(target, params+0);
                        uint32_t l = target_buffer_get_u32(target, params+4);
-                       char *arg = "foobar";
+                       char *arg = arm->semihosting_cmdline != NULL ? arm->semihosting_cmdline : "";
                        uint32_t s = strlen(arg) + 1;
                        if (l < s)
                                arm->semihosting_result = -1;
index 2029ca92a35dbf23ae62dd64286cf75e0190c34c..48050b078eba635261ebf87c2ad296f12e6326de 100644 (file)
@@ -1091,6 +1091,42 @@ COMMAND_HANDLER(handle_arm_semihosting_fileio_command)
        return ERROR_OK;
 }
 
+COMMAND_HANDLER(handle_arm_semihosting_cmdline)
+{
+       struct target *target = get_current_target(CMD_CTX);
+       unsigned int i;
+
+       if (target == NULL) {
+               LOG_ERROR("No target selected");
+               return ERROR_FAIL;
+       }
+
+       struct arm *arm = target_to_arm(target);
+
+       if (!is_arm(arm)) {
+               command_print(CMD_CTX, "current target isn't an ARM");
+               return ERROR_FAIL;
+       }
+
+       if (!arm->setup_semihosting) {
+               command_print(CMD_CTX, "semihosting not supported for current target");
+               return ERROR_FAIL;
+       }
+
+       free(arm->semihosting_cmdline);
+       arm->semihosting_cmdline = CMD_ARGC > 0 ? strdup(CMD_ARGV[0]) : NULL;
+
+       for (i = 1; i < CMD_ARGC; i++) {
+               char *cmdline = alloc_printf("%s %s", arm->semihosting_cmdline, CMD_ARGV[i]);
+               if (cmdline == NULL)
+                       break;
+               free(arm->semihosting_cmdline);
+               arm->semihosting_cmdline = cmdline;
+       }
+
+       return ERROR_OK;
+}
+
 static const struct command_registration arm_exec_command_handlers[] = {
        {
                .name = "reg",
@@ -1133,6 +1169,13 @@ static const struct command_registration arm_exec_command_handlers[] = {
                .usage = "['enable'|'disable']",
                .help = "activate support for semihosting operations",
        },
+       {
+               "semihosting_cmdline",
+               .handler = handle_arm_semihosting_cmdline,
+               .mode = COMMAND_EXEC,
+               .usage = "arguments",
+               .help = "command line arguments to be passed to program",
+       },
        {
                "semihosting_fileio",
                .handler = handle_arm_semihosting_fileio_command,