target/cortex: malloc/free tdesc on attach/detach instead of once on probe
This commit is contained in:
parent
8f4a8ab593
commit
2cf1aff698
|
@ -505,13 +505,6 @@ bool cortexa_probe(ADIv5_AP_t *apb, uint32_t debug_base)
|
|||
t->attach = cortexa_attach;
|
||||
t->detach = cortexa_detach;
|
||||
|
||||
// Find the buffer size needed for the target description string we need to send to GDB,
|
||||
// and then compute the string itself.
|
||||
size_t size_needed = create_tdesc_cortex_a(NULL, 0) + 1;
|
||||
char *buffer = malloc(size_needed);
|
||||
create_tdesc_cortex_a(buffer, size_needed);
|
||||
|
||||
t->tdesc = buffer;
|
||||
t->regs_read = cortexa_regs_read;
|
||||
t->regs_write = cortexa_regs_write;
|
||||
t->reg_read = cortexa_reg_read;
|
||||
|
@ -534,6 +527,16 @@ bool cortexa_attach(target *t)
|
|||
struct cortexa_priv *priv = t->priv;
|
||||
int tries;
|
||||
|
||||
if (!t->tdesc) {
|
||||
// Find the buffer size needed for the target description string we need to send to GDB,
|
||||
// and then compute the string itself.
|
||||
size_t size_needed = create_tdesc_cortex_a(NULL, 0) + 1;
|
||||
t->tdesc = malloc(size_needed);
|
||||
create_tdesc_cortex_a(t->tdesc, size_needed);
|
||||
} else {
|
||||
DEBUG_WARN("Cortex-A: target description already allocated before attach");
|
||||
}
|
||||
|
||||
/* Clear any pending fault condition */
|
||||
target_check_error(t);
|
||||
|
||||
|
@ -567,6 +570,14 @@ void cortexa_detach(target *t)
|
|||
{
|
||||
struct cortexa_priv *priv = t->priv;
|
||||
|
||||
if (t->tdesc) {
|
||||
// Free the target description string that was allocated in cortexa_attach().
|
||||
free(t->tdesc);
|
||||
t->tdesc = NULL;
|
||||
} else {
|
||||
DEBUG_WARN("Cortex-A: target description already NULL before detach");
|
||||
}
|
||||
|
||||
/* Clear any stale breakpoints */
|
||||
for(unsigned i = 0; i < priv->hw_breakpoint_max; i++) {
|
||||
apb_write(t, DBGBCR(i), 0);
|
||||
|
|
|
@ -594,21 +594,6 @@ bool cortexm_probe(ADIv5_AP_t *ap)
|
|||
|
||||
/* Should probe here to make sure it's Cortex-M3 */
|
||||
|
||||
// Find the buffer size needed for the target description string we need to send to GDB,
|
||||
// and then compute the string itself.
|
||||
size_t size_needed;
|
||||
char *buffer;
|
||||
if (!is_cortexmf) {
|
||||
size_needed = create_tdesc_cortex_m(NULL, 0) + 1;
|
||||
buffer = malloc(size_needed);
|
||||
create_tdesc_cortex_m(buffer, size_needed);
|
||||
} else {
|
||||
size_needed = create_tdesc_cortex_mf(NULL, 0) + 1;
|
||||
buffer = malloc(size_needed);
|
||||
create_tdesc_cortex_mf(buffer, size_needed);
|
||||
}
|
||||
|
||||
t->tdesc = buffer;
|
||||
t->regs_read = cortexm_regs_read;
|
||||
t->regs_write = cortexm_regs_write;
|
||||
t->reg_read = cortexm_reg_read;
|
||||
|
@ -755,6 +740,26 @@ bool cortexm_probe(ADIv5_AP_t *ap)
|
|||
|
||||
bool cortexm_attach(target *t)
|
||||
{
|
||||
bool is_cortexmf = (t->target_options & TOPT_FLAVOUR_V7MF) == TOPT_FLAVOUR_V7MF;
|
||||
|
||||
if (!t->tdesc) {
|
||||
// Find the buffer size needed for the target description string we need to send to GDB,
|
||||
// and then compute the string itself.
|
||||
size_t size_needed;
|
||||
if (!is_cortexmf) {
|
||||
size_needed = create_tdesc_cortex_m(NULL, 0) + 1;
|
||||
t->tdesc = malloc(size_needed);
|
||||
create_tdesc_cortex_m(t->tdesc, size_needed);
|
||||
} else {
|
||||
size_needed = create_tdesc_cortex_mf(NULL, 0) + 1;
|
||||
t->tdesc = malloc(size_needed);
|
||||
create_tdesc_cortex_mf(t->tdesc, size_needed);
|
||||
}
|
||||
} else {
|
||||
DEBUG_WARN("Cortex-M: target description already allocated before attach");
|
||||
}
|
||||
|
||||
|
||||
ADIv5_AP_t *ap = cortexm_ap(t);
|
||||
ap->dp->fault = 1; /* Force switch to this multi-drop device*/
|
||||
struct cortexm_priv *priv = t->priv;
|
||||
|
@ -820,6 +825,14 @@ void cortexm_detach(target *t)
|
|||
struct cortexm_priv *priv = t->priv;
|
||||
unsigned i;
|
||||
|
||||
if (t->tdesc) {
|
||||
// Free the target description string that was allocated in cortexm_attach().
|
||||
free(t->tdesc);
|
||||
t->tdesc = NULL;
|
||||
} else {
|
||||
DEBUG_WARN("Cortex-M: target description already NULL before detach");
|
||||
}
|
||||
|
||||
/* Clear any stale breakpoints */
|
||||
for (i = 0; i < priv->hw_breakpoint_max; i++)
|
||||
target_mem_write32(t, CORTEXM_FPB_COMP(i), 0);
|
||||
|
|
|
@ -98,7 +98,7 @@ struct target_s {
|
|||
|
||||
/* Register access functions */
|
||||
size_t regs_size;
|
||||
const char *tdesc;
|
||||
char *tdesc;
|
||||
void (*regs_read)(target *t, void *data);
|
||||
void (*regs_write)(target *t, const void *data);
|
||||
ssize_t (*reg_read)(target *t, int reg, void *data, size_t max);
|
||||
|
|
Loading…
Reference in New Issue