aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorGareth McMullin2012-06-27 21:26:08 +1200
committerGareth McMullin2012-06-27 21:26:08 +1200
commit466bb66424a8a44581ae2f9defbe95aa5384c395 (patch)
treeac1ef277e96e3522907596182ce701ca0bd3468b /src/include
parent4581da20342c459855a4b585e72746df56e22e26 (diff)
Made cur_target, last_target static in gdb_main.c.
Added target destroy notify mechanism.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/command.h2
-rw-r--r--src/include/target.h21
2 files changed, 18 insertions, 5 deletions
diff --git a/src/include/command.h b/src/include/command.h
index a44ed13..32b0d7b 100644
--- a/src/include/command.h
+++ b/src/include/command.h
@@ -24,7 +24,7 @@
#include "general.h"
#include "target.h"
-int command_process(char *cmd);
+int command_process(target *t, char *cmd);
typedef bool (*cmd_handler)(target *t, int argc, const char **argv);
struct command_s {
diff --git a/src/include/target.h b/src/include/target.h
index dc602aa..4a702a1 100644
--- a/src/include/target.h
+++ b/src/include/target.h
@@ -27,9 +27,19 @@
typedef struct target_s target;
+/* The destroy callback function will be called by target_list_free() just
+ * before the target is free'd. This may be because we're scanning for new
+ * targets, or because of a communication failure. The target data may
+ * be assumed to be intact, but the communication medium may not be available,
+ * so access methods shouldn't be called.
+ *
+ * The callback is installed by target_attach() and only removed by attaching
+ * with a different callback. It remains intact after target_detach().
+ */
+typedef void (*target_destroy_callback)(target *t);
+
/* Halt/resume functions */
-#define target_attach(target) \
- (target)->attach(target)
+target *target_attach(target *t, target_destroy_callback destroy_cb);
#define target_detach(target) \
(target)->detach(target)
@@ -37,7 +47,6 @@ typedef struct target_s target;
#define target_check_error(target) \
(target)->check_error(target)
-
/* Memory access functions */
#define target_mem_read_words(target, dest, src, len) \
(target)->mem_read_words((target), (dest), (src), (len))
@@ -108,7 +117,11 @@ typedef struct target_s target;
#define target_flash_write(target, dest, src, len) \
(target)->flash_write((target), (dest), (src), (len))
+
struct target_s {
+ /* Notify controlling debugger if target is lost */
+ target_destroy_callback destroy_callback;
+
/* Attach/Detach funcitons */
void (*attach)(struct target_s *target);
void (*detach)(struct target_s *target);
@@ -174,7 +187,7 @@ struct target_command_s {
struct target_command_s *next;
};
-extern target *target_list, *cur_target, *last_target;
+extern target *target_list;
target *target_new(unsigned size);
void target_list_free(void);