From 030031eed5425623865069a6083de8210c3769df Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 11 Jun 2013 18:05:57 +0000 Subject: [PATCH] Lazily allocate 'struct regsets_info'::disabled_regsets. There's no need for every arch to pre-allocate disabled_regsets. Chances are the array won't be used. (I have a hunch that with some more work we could dispense with initialize_regsets_info.) Tested on x86_64 Fedora 17 w/ -lmcheck. gdb/gdbserver/ 2013-06-11 Pedro Alves * linux-low.c (regset_disabled, disable_regset): New functions. (regsets_fetch_inferior_registers) (regsets_store_inferior_registers): Use them. (initialize_regsets_info); Don't allocate the disabled_regsets array here. * linux-low.h (struct regsets_info) : Extend comment. --- gdb/gdbserver/ChangeLog | 10 ++++++++++ gdb/gdbserver/linux-low.c | 39 ++++++++++++++++++++++++++------------- gdb/gdbserver/linux-low.h | 4 +++- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 169bb532658..f3e47a89755 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,13 @@ +2013-06-11 Pedro Alves + + * linux-low.c (regset_disabled, disable_regset): New functions. + (regsets_fetch_inferior_registers) + (regsets_store_inferior_registers): Use them. + (initialize_regsets_info); Don't allocate the disabled_regsets + array here. + * linux-low.h (struct regsets_info) : Extend + comment. + 2013-06-11 Pedro Alves * linux-low.c (initialize_regsets_info): Use xcalloc instead of diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 2114b07f5e5..bb7298a4da3 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -4051,6 +4051,28 @@ unstop_all_lwps (int unsuspend, struct lwp_info *except) #define use_linux_regsets 1 +/* Returns true if REGSET has been disabled. */ + +static int +regset_disabled (struct regsets_info *info, struct regset_info *regset) +{ + return (info->disabled_regsets != NULL + && info->disabled_regsets[regset - info->regsets]); +} + +/* Disable REGSET. */ + +static void +disable_regset (struct regsets_info *info, struct regset_info *regset) +{ + int dr_offset; + + dr_offset = regset - info->regsets; + if (info->disabled_regsets == NULL) + info->disabled_regsets = xcalloc (1, info->num_regsets); + info->disabled_regsets[dr_offset] = 1; +} + static int regsets_fetch_inferior_registers (struct regsets_info *regsets_info, struct regcache *regcache) @@ -4068,8 +4090,7 @@ regsets_fetch_inferior_registers (struct regsets_info *regsets_info, void *buf, *data; int nt_type, res; - if (regset->size == 0 - || regsets_info->disabled_regsets[regset - regsets_info->regsets]) + if (regset->size == 0 || regset_disabled (regsets_info, regset)) { regset ++; continue; @@ -4097,12 +4118,9 @@ regsets_fetch_inferior_registers (struct regsets_info *regsets_info, { if (errno == EIO) { - int dr_offset; - /* If we get EIO on a regset, do not try it again for this process mode. */ - dr_offset = regset - regsets_info->regsets; - regsets_info->disabled_regsets[dr_offset] = 1; + disable_regset (regsets_info, regset); free (buf); continue; } @@ -4143,8 +4161,7 @@ regsets_store_inferior_registers (struct regsets_info *regsets_info, void *buf, *data; int nt_type, res; - if (regset->size == 0 - || regsets_info->disabled_regsets[regset - regsets_info->regsets]) + if (regset->size == 0 || regset_disabled (regsets_info, regset)) { regset ++; continue; @@ -4191,12 +4208,9 @@ regsets_store_inferior_registers (struct regsets_info *regsets_info, { if (errno == EIO) { - int dr_offset; - /* If we get EIO on a regset, do not try it again for this process mode. */ - dr_offset = regset - regsets_info->regsets; - regsets_info->disabled_regsets[dr_offset] = 1; + disable_regset (regsets_info, regset); free (buf); continue; } @@ -6072,7 +6086,6 @@ initialize_regsets_info (struct regsets_info *info) info->regsets[info->num_regsets].size >= 0; info->num_regsets++) ; - info->disabled_regsets = xcalloc (1, info->num_regsets); } #endif diff --git a/gdb/gdbserver/linux-low.h b/gdb/gdbserver/linux-low.h index bce02881180..a8de3780c2e 100644 --- a/gdb/gdbserver/linux-low.h +++ b/gdb/gdbserver/linux-low.h @@ -60,7 +60,9 @@ struct regsets_info /* If we get EIO on a regset, do not try it again. Note the set of supported regsets may depend on processor mode on biarch - machines. */ + machines. This is a (lazily allocated) array holding one boolean + byte (0/1) per regset, with each element corresponding to the + regset in the REGSETS array above at the same offset. */ char *disabled_regsets; }; -- 2.30.2