diff options
Diffstat (limited to 'src/helper')
-rw-r--r-- | src/helper/command.c | 6 | ||||
-rw-r--r-- | src/helper/jim.c | 81 | ||||
-rw-r--r-- | src/helper/jim.h | 7 | ||||
-rw-r--r-- | src/helper/startup.tcl | 38 |
4 files changed, 104 insertions, 28 deletions
diff --git a/src/helper/command.c b/src/helper/command.c index c4edcc7f..9719d186 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -210,7 +210,7 @@ command_t* register_command(command_context_t *context, command_t *parent, char /* we now need to add an overrideable proc */ const char *override_name=alloc_printf("proc %s%s%s {args} {if {[catch {eval \"ocd_%s%s%s $args\"}]==0} {return \"\"} else { return -code error }", t1, t2, t3, t1, t2, t3); - Jim_Eval(interp, override_name); + Jim_Eval_Named(interp, override_name, __FILE__, __LINE__ ); free((void *)override_name); /* accumulate help text in Tcl helptext list. */ @@ -430,7 +430,7 @@ int command_run_line(command_context_t *context, char *line) retcode = Jim_SetAssocData(interp, "retval", NULL, &retval); if (retcode == JIM_OK) { - retcode = Jim_Eval(interp, line); + retcode = Jim_Eval_Named(interp, line, __FILE__, __LINE__ ); Jim_DeleteAssocData(interp, "retval"); } @@ -658,7 +658,7 @@ command_context_t* command_init() #ifdef JIM_EMBEDDED Jim_EventLoopOnLoad(interp); #endif - if (Jim_Eval(interp, startup_tcl)==JIM_ERR) + if (Jim_Eval_Named(interp, startup_tcl, "embedded:startup.tcl",1)==JIM_ERR) { LOG_ERROR("Failed to run startup.tcl (embedded into OpenOCD compile time)"); Jim_PrintErrorMessage(interp); diff --git a/src/helper/jim.c b/src/helper/jim.c index a9838ab0..791dfc6f 100644 --- a/src/helper/jim.c +++ b/src/helper/jim.c @@ -111,6 +111,33 @@ static Jim_HashTableType JimVariablesHashTableType; * Utility functions * ---------------------------------------------------------------------------*/ +static char * +jim_vasprintf( const char *fmt, va_list ap ) +{ +#ifndef HAVE_VASPRINTF + /* yucky way */ +static char buf[2048]; + vsnprintf( buf, sizeof(buf), fmt, ap ); + /* garentee termination */ + buf[sizeof(buf)-1] = 0; +#else + char *buf; + vasprintf( &buf, fmt, ap ); +#endif + return buf; +} + +static void +jim_vasprintf_done( void *buf ) +{ +#ifndef HAVE_VASPRINTF + (void)(buf); +#else + free(buf); +#endif +} + + /* * Convert a string to a jim_wide INTEGER. * This function originates from BSD. @@ -2019,6 +2046,22 @@ void Jim_AppendString(Jim_Interp *interp, Jim_Obj *objPtr, const char *str, StringAppendString(objPtr, str, len); } +void Jim_AppendString_sprintf( Jim_Interp *interp, Jim_Obj *objPtr, const char *fmt, ... ) +{ + char *buf; + va_list ap; + + va_start( ap, fmt ); + buf = jim_vasprintf( fmt, ap ); + va_end(ap); + + if( buf ){ + Jim_AppendString( interp, objPtr, buf, -1 ); + jim_vasprintf_done(buf); + } +} + + void Jim_AppendObj(Jim_Interp *interp, Jim_Obj *objPtr, Jim_Obj *appendObjPtr) { @@ -8726,17 +8769,31 @@ int JimCallProcedure(Jim_Interp *interp, Jim_Cmd *cmd, int argc, return retcode; } -int Jim_Eval(Jim_Interp *interp, const char *script) +int Jim_Eval_Named(Jim_Interp *interp, const char *script, const char *filename, int lineno) { - Jim_Obj *scriptObjPtr = Jim_NewStringObj(interp, script, -1); int retval; + Jim_Obj *scriptObjPtr; + scriptObjPtr = Jim_NewStringObj(interp, script, -1); Jim_IncrRefCount(scriptObjPtr); + + + if( filename ){ + JimSetSourceInfo( interp, scriptObjPtr, filename, lineno ); + } + retval = Jim_EvalObj(interp, scriptObjPtr); Jim_DecrRefCount(interp, scriptObjPtr); return retval; } +int Jim_Eval(Jim_Interp *interp, const char *script) +{ + return Jim_Eval_Named( interp, script, NULL, 0 ); +} + + + /* Execute script in the scope of the global level */ int Jim_EvalGlobal(Jim_Interp *interp, const char *script) { @@ -9076,6 +9133,7 @@ void JimRegisterCoreApi(Jim_Interp *interp) JIM_REGISTER_API(Alloc); JIM_REGISTER_API(Free); JIM_REGISTER_API(Eval); + JIM_REGISTER_API(Eval_Named); JIM_REGISTER_API(EvalGlobal); JIM_REGISTER_API(EvalFile); JIM_REGISTER_API(EvalObj); @@ -9102,6 +9160,7 @@ void JimRegisterCoreApi(Jim_Interp *interp) JIM_REGISTER_API(NewStringObj); JIM_REGISTER_API(NewStringObjNoAlloc); JIM_REGISTER_API(AppendString); + JIM_REGISTER_API(AppendString_sprintf); JIM_REGISTER_API(AppendObj); JIM_REGISTER_API(AppendStrings); JIM_REGISTER_API(StringEqObj); @@ -12536,27 +12595,15 @@ int Jim_SetResult_sprintf( Jim_Interp *interp, const char *fmt,... ) { va_list ap; -#ifndef HAVE_VASPRINTF - /* yucky way */ - char buf[2048]; - - va_start(ap,fmt); - vsnprintf( buf, sizeof(buf), fmt, ap ); - va_end(ap); - /* garentee termination */ - buf[2047] = 0; - Jim_SetResultString( interp, buf, -1 ); - -#else char *buf; + va_start(ap,fmt); - vasprintf( &buf, fmt, ap ); + buf = jim_vasprintf( fmt, ap ); va_end(ap); if( buf ){ Jim_SetResultString( interp, buf, -1 ); - free(buf); + jim_vasprintf_done(buf); } -#endif return JIM_OK; } diff --git a/src/helper/jim.h b/src/helper/jim.h index a89500fb..617cf002 100644 --- a/src/helper/jim.h +++ b/src/helper/jim.h @@ -675,6 +675,9 @@ JIM_STATIC char * JIM_API(Jim_StrDup) (const char *s); /* evaluation */ JIM_STATIC int JIM_API(Jim_Eval)(Jim_Interp *interp, const char *script); +/* in C code, you can do this and get better error messages */ +/* Jim_Eval_Named( interp, "some tcl commands", __FILE__, __LINE__ ); */ +JIM_STATIC int JIM_API(Jim_Eval_Named)(Jim_Interp *interp, const char *script,const char *filename, int lineno); JIM_STATIC int JIM_API(Jim_EvalGlobal)(Jim_Interp *interp, const char *script); JIM_STATIC int JIM_API(Jim_EvalFile)(Jim_Interp *interp, const char *filename); JIM_STATIC int JIM_API(Jim_EvalObj) (Jim_Interp *interp, Jim_Obj *scriptObjPtr); @@ -733,6 +736,8 @@ JIM_STATIC Jim_Obj * JIM_API(Jim_NewStringObjNoAlloc) (Jim_Interp *interp, char *s, int len); JIM_STATIC void JIM_API(Jim_AppendString) (Jim_Interp *interp, Jim_Obj *objPtr, const char *str, int len); +JIM_STATIC void JIM_API(Jim_AppendString_sprintf) (Jim_Interp *interp, Jim_Obj *objPtr, + const char *fmt, ... ); JIM_STATIC void JIM_API(Jim_AppendObj) (Jim_Interp *interp, Jim_Obj *objPtr, Jim_Obj *appendObjPtr); JIM_STATIC void JIM_API(Jim_AppendStrings) (Jim_Interp *interp, @@ -1169,6 +1174,7 @@ static void Jim_InitExtension(Jim_Interp *interp) JIM_GET_API(Alloc); JIM_GET_API(Free); JIM_GET_API(Eval); + JIM_GET_API(Eval_Named); JIM_GET_API(EvalGlobal); JIM_GET_API(EvalFile); JIM_GET_API(EvalObj); @@ -1195,6 +1201,7 @@ static void Jim_InitExtension(Jim_Interp *interp) JIM_GET_API(NewStringObj); JIM_GET_API(NewStringObjNoAlloc); JIM_GET_API(AppendString); + JIM_GET_API(AppendString_sprintf); JIM_GET_API(AppendObj); JIM_GET_API(AppendStrings); JIM_GET_API(StringEqObj); diff --git a/src/helper/startup.tcl b/src/helper/startup.tcl index 1b5c06e2..63956a9e 100644 --- a/src/helper/startup.tcl +++ b/src/helper/startup.tcl @@ -109,18 +109,40 @@ proc unknown {args} { return -code error "Unknown command: $args" } +proc new_target_name { } { + return [target number [expr [target count] - 1 ]] +} + 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 target_num]_[set eventname]" {} "script $scriptname" - + set tname [target number $target_num] + + if { 0 == [string compare $eventname "reset"] } { + $tname configure -event old-post_reset "script $scriptname" + return + } + + if { 0 == [string compare $eventname "post_reset"] } { + $tname configure -event old-post_reset "script $scriptname" + return + } + + if { 0 == [string compare $eventname "pre_reset"] } { + $tname configure -event old-pre_reset "script $scriptname" + return + } + + if { 0 == [string compare $eventname "gdb_program_config"] } { + $tname configure -event old-gdb_program_config "script $scriptname" + return + } + + return -code error "Unknown target (old) event: $eventname (try $tname configure -event NAME)" + } -add_help_text target_script "<target#> <event=reset/pre_reset/post_halt/pre_resume/gdb_program_config> <script_file>" +add_help_text target_script "DEPRECATED please see the new TARGETNAME configure -event interface" # Try flipping / and \ to find file if the filename does not @@ -170,4 +192,4 @@ proc jtag_rclk {fallback_speed_khz} { } } -add_help_text jtag_rclk "fallback_speed_khz - set JTAG speed to RCLK or use fallback speed"
\ No newline at end of file +add_help_text jtag_rclk "fallback_speed_khz - set JTAG speed to RCLK or use fallback speed" |