mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-05 15:15:42 +00:00
Use unordered_map in record-btrace
This changes the bfcache in record-btrace.c to use a gdb::unordered_map. Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
@@ -1662,55 +1662,22 @@ struct btrace_frame_cache
|
|||||||
/* The thread. */
|
/* The thread. */
|
||||||
struct thread_info *tp;
|
struct thread_info *tp;
|
||||||
|
|
||||||
/* The frame info. */
|
|
||||||
frame_info *frame;
|
|
||||||
|
|
||||||
/* The branch trace function segment. */
|
/* The branch trace function segment. */
|
||||||
const struct btrace_function *bfun;
|
const struct btrace_function *bfun;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* A struct btrace_frame_cache hash table indexed by NEXT. */
|
/* A struct btrace_frame_cache hash table indexed by NEXT. */
|
||||||
|
|
||||||
static htab_t bfcache;
|
static gdb::unordered_map<frame_info *, btrace_frame_cache *> bfcache;
|
||||||
|
|
||||||
/* hash_f for htab_create_alloc of bfcache. */
|
|
||||||
|
|
||||||
static hashval_t
|
|
||||||
bfcache_hash (const void *arg)
|
|
||||||
{
|
|
||||||
const struct btrace_frame_cache *cache
|
|
||||||
= (const struct btrace_frame_cache *) arg;
|
|
||||||
|
|
||||||
return htab_hash_pointer (cache->frame);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* eq_f for htab_create_alloc of bfcache. */
|
|
||||||
|
|
||||||
static int
|
|
||||||
bfcache_eq (const void *arg1, const void *arg2)
|
|
||||||
{
|
|
||||||
const struct btrace_frame_cache *cache1
|
|
||||||
= (const struct btrace_frame_cache *) arg1;
|
|
||||||
const struct btrace_frame_cache *cache2
|
|
||||||
= (const struct btrace_frame_cache *) arg2;
|
|
||||||
|
|
||||||
return cache1->frame == cache2->frame;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create a new btrace frame cache. */
|
/* Create a new btrace frame cache. */
|
||||||
|
|
||||||
static struct btrace_frame_cache *
|
static struct btrace_frame_cache *
|
||||||
bfcache_new (const frame_info_ptr &frame)
|
bfcache_new (const frame_info_ptr &frame)
|
||||||
{
|
{
|
||||||
struct btrace_frame_cache *cache;
|
struct btrace_frame_cache *cache
|
||||||
void **slot;
|
= FRAME_OBSTACK_ZALLOC (struct btrace_frame_cache);
|
||||||
|
bfcache.emplace (frame.get (), cache);
|
||||||
cache = FRAME_OBSTACK_ZALLOC (struct btrace_frame_cache);
|
|
||||||
cache->frame = frame.get ();
|
|
||||||
|
|
||||||
slot = htab_find_slot (bfcache, cache, INSERT);
|
|
||||||
gdb_assert (*slot == NULL);
|
|
||||||
*slot = cache;
|
|
||||||
|
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
@@ -1720,18 +1687,10 @@ bfcache_new (const frame_info_ptr &frame)
|
|||||||
static const struct btrace_function *
|
static const struct btrace_function *
|
||||||
btrace_get_frame_function (const frame_info_ptr &frame)
|
btrace_get_frame_function (const frame_info_ptr &frame)
|
||||||
{
|
{
|
||||||
const struct btrace_frame_cache *cache;
|
auto iter = bfcache.find (frame.get ());
|
||||||
struct btrace_frame_cache pattern;
|
if (iter == bfcache.end ())
|
||||||
void **slot;
|
return nullptr;
|
||||||
|
return iter->second->bfun;
|
||||||
pattern.frame = frame.get ();
|
|
||||||
|
|
||||||
slot = htab_find_slot (bfcache, &pattern, NO_INSERT);
|
|
||||||
if (slot == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
cache = (const struct btrace_frame_cache *) *slot;
|
|
||||||
return cache->bfun;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Implement stop_reason method for record_btrace_frame_unwind. */
|
/* Implement stop_reason method for record_btrace_frame_unwind. */
|
||||||
@@ -1928,15 +1887,7 @@ record_btrace_tailcall_frame_sniffer (const struct frame_unwind *self,
|
|||||||
static void
|
static void
|
||||||
record_btrace_frame_dealloc_cache (frame_info *self, void *this_cache)
|
record_btrace_frame_dealloc_cache (frame_info *self, void *this_cache)
|
||||||
{
|
{
|
||||||
struct btrace_frame_cache *cache;
|
bfcache.erase (self);
|
||||||
void **slot;
|
|
||||||
|
|
||||||
cache = (struct btrace_frame_cache *) this_cache;
|
|
||||||
|
|
||||||
slot = htab_find_slot (bfcache, cache, NO_INSERT);
|
|
||||||
gdb_assert (slot != NULL);
|
|
||||||
|
|
||||||
htab_remove_elt (bfcache, cache);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* btrace recording does not store previous memory content, neither the stack
|
/* btrace recording does not store previous memory content, neither the stack
|
||||||
@@ -3327,9 +3278,6 @@ effect on an active recording."),
|
|||||||
|
|
||||||
add_target (record_btrace_target_info, record_btrace_target_open);
|
add_target (record_btrace_target_info, record_btrace_target_open);
|
||||||
|
|
||||||
bfcache = htab_create_alloc (50, bfcache_hash, bfcache_eq, NULL,
|
|
||||||
xcalloc, xfree);
|
|
||||||
|
|
||||||
record_btrace_conf.bts.size = 64 * 1024;
|
record_btrace_conf.bts.size = 64 * 1024;
|
||||||
record_btrace_conf.pt.size = 16 * 1024;
|
record_btrace_conf.pt.size = 16 * 1024;
|
||||||
#if (LIBIPT_VERSION >= 0x200)
|
#if (LIBIPT_VERSION >= 0x200)
|
||||||
|
|||||||
Reference in New Issue
Block a user