aboutsummaryrefslogtreecommitdiff
path: root/gdb/arch/riscv.h
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2018-11-29 15:51:58 +0000
committerAndrew Burgess <andrew.burgess@embecosm.com>2018-11-30 18:13:43 +0000
commit634494366c515a89c4747d8a68a8da9218bb4969 (patch)
tree6b50bc20d3ed050d7ce045f44673ed4d44ae8d72 /gdb/arch/riscv.h
parent65a4b373267813ae5e47ac519da2e70d9c7e09d3 (diff)
downloadgdb-634494366c515a89c4747d8a68a8da9218bb4969.zip
gdb-634494366c515a89c4747d8a68a8da9218bb4969.tar.gz
gdb-634494366c515a89c4747d8a68a8da9218bb4969.tar.bz2
gdb/riscv: Create each unique target description only once
GDB relies on the fact that if two target descriptions have the same contents, then they will be the same object instance (having the same address). One place where this is a requirement is in GDBARCH_LIST_LOOKUP_BY_INFO which is used to find previously created gdbarch objects. In GDBARCH_LIST_LOOKUP_BY_INFO a pointer comparison is made on the gdbarch's target description, if the pointers are different then it is assumed the gdbarches have different, non-compatible target descriptions. Previously we would create duplicate target descriptions in the belief that RISCV_GDBARCH_INIT would spot this duplication and discard the second instance. However, this was incorrect, and instead we ended up creating duplicate gdbarch objects. With this commit every unique feature set will create one and only one target description, the feature set and resulting target description is then cached so that the same target description object can be returned later. Many other target avoid this problem by creating a small number of named target descriptions, and returning one of these. However, we currently have 8 possible target descriptions (32 vs 64 bit for x-reg and f-reg, and h/w or s/w float abi) and creating each of these just to avoid a dynamic cache seems pointless. gdb/ChangeLog: * arch/riscv.h (riscv_gdbarch_features::hash): New method. * arch/riscv.c (struct riscv_gdbarch_features_hasher): New. (riscv_tdesc_cache): New global. (riscv_create_target_description): Look in the cache before creating a new target description.
Diffstat (limited to 'gdb/arch/riscv.h')
-rw-r--r--gdb/arch/riscv.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/gdb/arch/riscv.h b/gdb/arch/riscv.h
index be41828e..79f5ec6 100644
--- a/gdb/arch/riscv.h
+++ b/gdb/arch/riscv.h
@@ -66,6 +66,15 @@ struct riscv_gdbarch_features
{
return !((*this) == rhs);
}
+
+ /* Used by std::unordered_map to hash feature sets. */
+ std::size_t hash () const noexcept
+ {
+ std::size_t val = ((xlen & 0x1f) << 6
+ | (flen & 0x1f) << 1
+ | (hw_float_abi ? 1 : 0));
+ return val;
+ }
};
/* Create and return a target description that is compatible with