On 04.11.2017 22:40, Andreas Fritiofson wrote:
On Sat, Nov 4, 2017 at 10:13 PM, Tomas Vanek
<[email protected] <mailto:[email protected]>>
wrote:
On 04.11.2017 21:53, Andreas Fritiofson wrote:
Why isn't the corresponding target always passed to the Tcl event
handler (in target_handle_event)? Seems like a handler would
always need that if it's doing more than echoing something.
Odd... How does the current handlers work if there's more than
one target? I.e. those that simply do mww etc. in the handler. Is
the "current target" somehow always pointing to the relevant
target when the handler is executing? If yes, well you could use
that, if not then all stock handlers are broken.
No, my tests show the current target is unchanged during event
handling. Lot of target handlers work with current target
regardless of the target they was invoked from.
So that means they are broken? How would fixing it using my suggestion
above sound? Passing the target name to the handlers, always, and
rewriting all handlers to use $t mww and so on.
I investigated the problem further.
The 'struct target_event_action' contains for each defined event 'struct
Jim_Interp *interp'.
It is used in target_handle_event() as a Tcl interpreter.
I'm not sure if it was originally meant as a kind of context save (and
it worked in some ancient version of OpenOCD?)
or it is just a more complicated way to get global_cmd_ctx->interp
Anyway interp always points to the only Tcl interpreter used.
If we add setting
cmd_ctx->current_target = target->target_number;
to target_handle_event() and restore original value just before return,
we get the magic of correctly set current target during event handling.
Is there a more elegant way without the need of restoring original
cmd_ctx->current_target?
We can make a copy by copy_command_context(), set
Jim_SetAssocData(interp, "context", NULL, ctx_with_curent_target_set);
Unfortunately we have to restore assoc data back when done - much more
complicated...
Tom
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel