]> git.sur5r.net Git - openocd/commitdiff
better error messages for target event scripts.
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Wed, 16 Jul 2008 07:22:17 +0000 (07:22 +0000)
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Wed, 16 Jul 2008 07:22:17 +0000 (07:22 +0000)
git-svn-id: svn://svn.berlios.de/openocd/trunk@810 b42882b7-edfa-0310-969c-e2dbd0fdcd60

src/helper/command.c
src/openocd.c
src/startup.tcl
src/target/target.c

index 45b66d60006ac3f74584d8991a96e66fa0e75c1d..c1eacc00a821f5fc65eff31e0a6da414656a9c17 100644 (file)
@@ -100,6 +100,8 @@ command_t* register_command(command_context_t *context, command_t *parent, char
        }
        /* accumulate help text in Tcl helptext list.  */
     Jim_Obj *helptext=Jim_GetGlobalVariableStr(interp, "ocd_helptext", JIM_ERRMSG);
+    if (Jim_IsShared(helptext))
+        helptext = Jim_DuplicateObj(interp, helptext);
        Jim_Obj *cmd_entry=Jim_NewListObj(interp, NULL, 0);
        
        Jim_Obj *cmd_list=Jim_NewListObj(interp, NULL, 0);
index b36347cd7186a27d03cbcd0da74755cae20599c4..2d7e774734b32f9db1531318907589f20b255669 100644 (file)
@@ -734,6 +734,9 @@ void add_jim(const char *name, int (*cmd)(Jim_Interp *interp, int argc, Jim_Obj
        /* FIX!!! it would be prettier to invoke add_help_text... 
        accumulate help text in Tcl helptext list.  */
     Jim_Obj *helptext=Jim_GetGlobalVariableStr(interp, "ocd_helptext", JIM_ERRMSG);
+    if (Jim_IsShared(helptext))
+        helptext = Jim_DuplicateObj(interp, helptext);
+    
        Jim_Obj *cmd_entry=Jim_NewListObj(interp, NULL, 0);
        
        Jim_Obj *cmd_list=Jim_NewListObj(interp, NULL, 0);
index dc3a0895729001693054145838ae171faacf1276..1f1d1e214037916373639b03973b952312cca30c 100644 (file)
@@ -11,7 +11,6 @@
 # Commands can be more than one word and they are stored
 # as "flash banks" "help text x x x"
 
-global ocd_helptext
 set ocd_helptext {}
 
 proc add_help_text {cmd cmd_help} {
@@ -123,3 +122,18 @@ proc unknown {args} {
        # the command twice.
        return ""
 }
+
+
+proc target_script {target_num eventname scriptname} {
+       if {[string compare $eventname reset]==0} {
+               set eventname post_reset
+       }
+
+       # This is the script we invoke
+       proc "target_[set eventname]_[set target_num]" {} "script $scriptname" 
+       
+}
+
+#add_help_text target_script "xxx"
+add_help_text target_script "<target#> <event=reset/pre_reset/post_halt/pre_resume/gdb_program_config> <script_file>"
+
index bd334da25700ff80e6420ee0501622fb8eb945a8..06a0d487d31ed5656c7852632f46071ebd127f3b 100644 (file)
@@ -52,7 +52,6 @@ int cli_target_callback_event_handler(struct target_s *target, enum target_event
 int handle_target_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 
-int handle_target_script_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 int handle_run_and_halt_time_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 int handle_working_area_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 
@@ -952,8 +951,6 @@ int target_register_commands(struct command_context_s *cmd_ctx)
 {
        register_command(cmd_ctx, NULL, "target", handle_target_command, COMMAND_CONFIG, "target <cpu> [reset_init default - DEPRECATED] <chainpos> <endianness> <variant> [cpu type specifc args]");
        register_command(cmd_ctx, NULL, "targets", handle_targets_command, COMMAND_EXEC, NULL);
-       register_command(cmd_ctx, NULL, "target_script", handle_target_script_command, COMMAND_CONFIG, 
-       "target_script <target#> <event=reset/pre_reset/post_halt/pre_resume/gdb_program_config> <script_file>");
        register_command(cmd_ctx, NULL, "run_and_halt_time", handle_run_and_halt_time_command, COMMAND_CONFIG, "<target> <run time ms>");
        register_command(cmd_ctx, NULL, "working_area", handle_working_area_command, COMMAND_ANY, "working_area <target#> <address> <size> <'backup'|'nobackup'> [virtual address]");
        register_command(cmd_ctx, NULL, "virt2phys", handle_virt2phys_command, COMMAND_ANY, "virt2phys <virtual address>");
@@ -1491,42 +1488,6 @@ int target_invoke_script(struct command_context_s *cmd_ctx, target_t *target, ch
        name, get_num_by_target(target));
 }
 
-int handle_target_script_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
-{
-       target_t *target = NULL;
-       
-       if (argc < 3)
-       {
-               LOG_ERROR("incomplete target_script command");
-               return ERROR_COMMAND_SYNTAX_ERROR;
-       }
-       
-       target = get_target_by_num(strtoul(args[0], NULL, 0));
-       
-       if (!target)
-       {
-               return ERROR_COMMAND_SYNTAX_ERROR;
-       }
-       
-       const char *event=args[1];
-       if (strcmp("reset", event)==0)
-       {
-               /* synonymous */
-               event="post_reset";
-       }
-                       
-       /* Define a tcl procedure which we'll invoke upon some event */
-       command_run_linef(cmd_ctx, 
-       "proc target_%s_%d {} {"
-       "openocd {script %s} ; return \"\"" 
-       "}",
-       event,
-       get_num_by_target(target),
-       args[2]);
-       
-       return ERROR_OK;
-}
-
 int handle_run_and_halt_time_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
        target_t *target = NULL;