diff options
author | Yao Qi <yao@codesourcery.com> | 2013-10-29 21:34:20 +0800 |
---|---|---|
committer | Yao Qi <yao@codesourcery.com> | 2013-11-20 11:40:43 +0800 |
commit | 2a2f9fe4007a0135ac091878dc7000f91e75e339 (patch) | |
tree | 9ea6cec1fab0a4a2c3ef5f78af7ad693589abf39 /gdb/target.c | |
parent | 3e9ecad3e843a588fa610c2419f7d3117014a927 (diff) | |
download | binutils-gdb-2a2f9fe4007a0135ac091878dc7000f91e75e339.tar.gz |
Remove last_cache
This patch removes global variable 'last_cache', and initialize
'target_dcache' lazily, so that 'target_dcache' can replace
'last_cache'. No functionalities should be changed after this patch.
gdb:
2013-11-20 Yao Qi <yao@codesourcery.com>
* dcache.c (last_cache): Remove.
(dcache_free, dcache_init): Update.
(dcache_update):
(dcache_print_line): Add parameter 'dcache'. Replace
'target_dcache' with 'dcache'.
(dcache_info): Move code to dcache_info_1. Call
'dcache_info_1'.
(dcache_info_1): New function.
(set_dcache_size): Call target_dcache_invalidate.
(set_dcache_line_size): Call target_dcache_invalidate.
* target.c (target_dcache_init_p): New function.
(target_dcache_invalidate): Check target_dcache_init_p first.
(target_dcache_get, target_dcache_get_or_init): New function.
(memory_xfer_partial_1): Adjust.
(initialize_target): Don't initialize 'target_dcache'.
* target.h (struct dcache_struct): Declare.
(target_dcache_get): Declare.
Diffstat (limited to 'gdb/target.c')
-rw-r--r-- | gdb/target.c | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/gdb/target.c b/gdb/target.c index 52d1081548a..cb758536ce5 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -238,12 +238,42 @@ show_stack_cache_enabled_p (struct ui_file *file, int from_tty, /* Cache of memory operations, to speed up remote access. */ static DCACHE *target_dcache; +/* Target dcache is initialized or not. */ + +static int +target_dcache_init_p (void) +{ + return (target_dcache != NULL); +} + /* Invalidate the target dcache. */ void target_dcache_invalidate (void) { - dcache_invalidate (target_dcache); + if (target_dcache_init_p ()) + dcache_invalidate (target_dcache); +} + +/* Return the target dcache. Return NULL if target dcache is not + initialized yet. */ + +DCACHE * +target_dcache_get (void) +{ + return target_dcache; +} + +/* Return the target dcache. If it is not initialized yet, initialize + it. */ + +static DCACHE * +target_dcache_get_or_init (void) +{ + if (!target_dcache_init_p ()) + target_dcache = dcache_init (); + + return target_dcache; } /* The user just typed 'target' without the name of a target. */ @@ -1588,15 +1618,15 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object, && (region->attrib.cache || (stack_cache_enabled_p && object == TARGET_OBJECT_STACK_MEMORY))) { + DCACHE *dcache = target_dcache_get_or_init (); + if (readbuf != NULL) - res = dcache_xfer_memory (ops, target_dcache, memaddr, readbuf, - reg_len, 0); + res = dcache_xfer_memory (ops, dcache, memaddr, readbuf, reg_len, 0); else /* FIXME drow/2006-08-09: If we're going to preserve const correctness dcache_xfer_memory should take readbuf and writebuf. */ - res = dcache_xfer_memory (ops, target_dcache, memaddr, - (void *) writebuf, + res = dcache_xfer_memory (ops, dcache, memaddr, (void *) writebuf, reg_len, 1); if (res <= 0) return -1; @@ -1641,7 +1671,9 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object, && stack_cache_enabled_p && object != TARGET_OBJECT_STACK_MEMORY) { - dcache_update (target_dcache, memaddr, (void *) writebuf, res); + DCACHE *dcache = target_dcache_get_or_init (); + + dcache_update (dcache, memaddr, (void *) writebuf, res); } /* If we still haven't got anything, return the last error. We @@ -5193,7 +5225,4 @@ When this permission is on, GDB may interrupt/stop the target's execution.\n\ Otherwise, any attempt to interrupt or stop will be ignored."), set_target_permissions, NULL, &setlist, &showlist); - - - target_dcache = dcache_init (); } |