This should facilitate dynamic target creation and removal.
Currently it helps with getting 0 bytes lost report from Valgrind on
exit (after talking to a nucleo board). However, 1,223,886 bytes in
5,268 blocks are still reachable which means the app holds pointers to
that data on exit. The majority comes from the jtag command queue,
there're also many blocks from TCL command registration.
Change-Id: I7523234bb90fffd26f7d29cdd7648ddd221d46ab
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/2544
Tested-by: jenkins
Reviewed-by: Stian Skjelstad <stian@nixia.no>
int server_quit(void)
{
remove_services();
+ target_quit();
#ifdef _WIN32
WSACleanup();
return ERROR_OK;
}
+void cortex_m_deinit_target(struct target *target)
+{
+ struct cortex_m_common *cortex_m = target_to_cm(target);
+
+ free(cortex_m->fp_comparator_list);
+ cortex_m_dwt_free(target);
+ free(cortex_m);
+}
+
/* REVISIT cache valid/dirty bits are unmaintained. We could set "valid"
* on r/w if the core is not running, and clear on resume or reset ... or
* at least, in a post_restore_context() method.
.target_create = cortex_m_target_create,
.init_target = cortex_m_init_target,
.examine = cortex_m_examine,
+ .deinit_target = cortex_m_deinit_target,
};
void cortex_m_enable_breakpoints(struct target *target);
void cortex_m_enable_watchpoints(struct target *target);
void cortex_m_dwt_setup(struct cortex_m_common *cm, struct target *target);
+void cortex_m_deinit_target(struct target *target);
#endif /* CORTEX_M_H */
.deprecated_name = "stm32_stlink",
.init_target = adapter_init_target,
+ .deinit_target = cortex_m_deinit_target,
.target_create = adapter_target_create,
.examine = cortex_m_examine,
.commands = adapter_command_handlers,
return target_free_working_area_restore(target, area, 1);
}
+void target_quit(void)
+{
+ struct target_event_callback *pe = target_event_callbacks;
+ while (pe) {
+ struct target_event_callback *t = pe->next;
+ free(pe);
+ pe = t;
+ }
+ target_event_callbacks = NULL;
+
+ struct target_timer_callback *pt = target_timer_callbacks;
+ while (pt) {
+ struct target_timer_callback *t = pt->next;
+ free(pt);
+ pt = t;
+ }
+ target_timer_callbacks = NULL;
+
+ for (struct target *target = all_targets;
+ target; target = target->next) {
+ if (target->type->deinit_target)
+ target->type->deinit_target(target);
+ }
+}
+
/* free resources and restore memory, if restoring memory fails,
* free up resources anyway
*/
void target_free_all_working_areas(struct target *target);
uint32_t target_get_working_area_avail(struct target *target);
+/**
+ * Free all the resources allocated by targets and the target layer
+ */
+void target_quit(void);
+
extern struct target *all_targets;
uint64_t target_buffer_get_u64(struct target *target, const uint8_t *buffer);
* */
int (*init_target)(struct command_context *cmd_ctx, struct target *target);
+ /**
+ * Free all the resources allocated by the target.
+ *
+ * @param target The target to deinit
+ */
+ void (*deinit_target)(struct target *target);
+
/* translate from virtual to physical address. Default implementation is successful
* no-op(i.e. virtual==physical).
*/