* [PATCH] Use std::vector on tdesc->reg_defs (gdbserver/tdesc.h)
@ 2017-09-10 17:12 Sergio Durigan Junior
2017-09-10 18:43 ` Simon Marchi
0 siblings, 1 reply; 4+ messages in thread
From: Sergio Durigan Junior @ 2017-09-10 17:12 UTC (permalink / raw)
To: GDB Patches; +Cc: Yao Qi, Sergio Durigan Junior
This is a followup patch to the build breakage fix on AArch64. While
doing the fix, I found it better to convert tdesc->reg_defs (on
gdbserver/tdesc.h) from using VEC to using std::vector. This makes
the code easier to read and maintain, and also is one more step
towards the C++fication.
Regtested on BuildBot.
yyyy-mm-dd Sergio Durigan Junior <sergiodj@redhat.com>
* regcache.c (get_thread_regcache): Update code to use "std::vector"
instead of "VEC" for "target_desc.reg_defs".
(regcache_cpy): Likewise.
(registers_to_string): Likewise.
(registers_from_string): Likewise.
(find_regno): Likewise.
(supply_regblock): Likewise.
(regcache_raw_read_unsigned): Likewise.
* tdesc.c (init_target_desc): Likewise.
(tdesc_create_reg): Likewise.
* tdesc.h: Remove declaration of "tdesc_reg_p". Include <vector>.
(struct target_desc) <reg_defs>: Convert to "std::vector".
(target_desc): Do not initialize "reg_defs".
(~target_desc): Update code to use "std::vector" instead of "VEC"
for "target_desc.reg_defs".
(operator==): Likewise.
---
gdb/gdbserver/regcache.c | 33 +++++++++++++++++----------------
gdb/gdbserver/tdesc.c | 14 ++++++--------
gdb/gdbserver/tdesc.h | 26 +++++++++-----------------
3 files changed, 32 insertions(+), 41 deletions(-)
diff --git a/gdb/gdbserver/regcache.c b/gdb/gdbserver/regcache.c
index 43e78a5cf7..75480912fb 100644
--- a/gdb/gdbserver/regcache.c
+++ b/gdb/gdbserver/regcache.c
@@ -54,7 +54,7 @@ get_thread_regcache (struct thread_info *thread, int fetch)
current_thread = thread;
/* Invalidate all registers, to prevent stale left-overs. */
memset (regcache->register_status, REG_UNAVAILABLE,
- VEC_length (tdesc_reg_p, regcache->tdesc->reg_defs));
+ regcache->tdesc->reg_defs.size ());
fetch_inferior_registers (regcache, -1);
current_thread = saved_thread;
regcache->registers_valid = 1;
@@ -145,9 +145,9 @@ init_register_cache (struct regcache *regcache,
= (unsigned char *) xcalloc (1, tdesc->registers_size);
regcache->registers_owned = 1;
regcache->register_status
- = (unsigned char *) xmalloc (VEC_length (tdesc_reg_p, tdesc->reg_defs));
+ = (unsigned char *) xmalloc (tdesc->reg_defs.size ());
memset ((void *) regcache->register_status, REG_UNAVAILABLE,
- VEC_length (tdesc_reg_p, tdesc->reg_defs));
+ tdesc->reg_defs.size ());
#else
gdb_assert_not_reached ("can't allocate memory from the heap");
#endif
@@ -204,7 +204,7 @@ regcache_cpy (struct regcache *dst, struct regcache *src)
#ifndef IN_PROCESS_AGENT
if (dst->register_status != NULL && src->register_status != NULL)
memcpy (dst->register_status, src->register_status,
- VEC_length (tdesc_reg_p, src->tdesc->reg_defs));
+ src->tdesc->reg_defs.size ());
#endif
dst->registers_valid = src->registers_valid;
}
@@ -217,11 +217,11 @@ registers_to_string (struct regcache *regcache, char *buf)
{
unsigned char *registers = regcache->registers;
const struct target_desc *tdesc = regcache->tdesc;
- int i;
- reg *reg;
- for (i = 0; VEC_iterate (tdesc_reg_p, tdesc->reg_defs, i, reg); i++)
+ for (int i = 0; i < tdesc->reg_defs.size (); ++i)
{
+ struct reg *reg = tdesc->reg_defs[i];
+
if (regcache->register_status[i] == REG_VALID)
{
bin2hex (registers, buf, register_size (tdesc, i));
@@ -257,12 +257,13 @@ registers_from_string (struct regcache *regcache, char *buf)
int
find_regno (const struct target_desc *tdesc, const char *name)
{
- int i;
- reg *reg;
+ for (int i = 0; i < tdesc->reg_defs.size (); ++i)
+ {
+ struct reg *reg = tdesc->reg_defs[i];
- for (i = 0; VEC_iterate (tdesc_reg_p, tdesc->reg_defs, i, reg); i++)
- if (strcmp (name, reg->name) == 0)
- return i;
+ if (strcmp (name, reg->name) == 0)
+ return i;
+ }
internal_error (__FILE__, __LINE__, "Unknown register %s requested",
name);
}
@@ -272,7 +273,7 @@ find_regno (const struct target_desc *tdesc, const char *name)
struct reg *
find_register_by_number (const struct target_desc *tdesc, int n)
{
- return VEC_index (tdesc_reg_p, tdesc->reg_defs, n);
+ return tdesc->reg_defs[n];
}
#ifndef IN_PROCESS_AGENT
@@ -388,7 +389,7 @@ supply_regblock (struct regcache *regcache, const void *buf)
{
int i;
- for (i = 0; i < VEC_length (tdesc_reg_p, tdesc->reg_defs); i++)
+ for (i = 0; i < tdesc->reg_defs.size (); i++)
regcache->register_status[i] = REG_VALID;
}
#endif
@@ -402,7 +403,7 @@ supply_regblock (struct regcache *regcache, const void *buf)
{
int i;
- for (i = 0; i < VEC_length (tdesc_reg_p, tdesc->reg_defs); i++)
+ for (i = 0; i < tdesc->reg_defs.size (); i++)
regcache->register_status[i] = REG_UNAVAILABLE;
}
#endif
@@ -435,7 +436,7 @@ regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
gdb_assert (regcache != NULL);
gdb_assert (regnum >= 0
- && regnum < VEC_length (tdesc_reg_p, regcache->tdesc->reg_defs));
+ && regnum < regcache->tdesc->reg_defs.size ());
size = register_size (regcache->tdesc, regnum);
diff --git a/gdb/gdbserver/tdesc.c b/gdb/gdbserver/tdesc.c
index 53f36d5564..63d6467d56 100644
--- a/gdb/gdbserver/tdesc.c
+++ b/gdb/gdbserver/tdesc.c
@@ -22,11 +22,9 @@
void
init_target_desc (struct target_desc *tdesc)
{
- int offset, i;
- struct reg *reg;
+ int offset = 0;
- offset = 0;
- for (i = 0; VEC_iterate (tdesc_reg_p, tdesc->reg_defs, i, reg); i++)
+ for (reg *reg : tdesc->reg_defs)
{
reg->offset = offset;
offset += reg->size;
@@ -193,23 +191,23 @@ tdesc_create_reg (struct tdesc_feature *feature, const char *name,
{
struct target_desc *tdesc = (struct target_desc *) feature;
- while (VEC_length (tdesc_reg_p, tdesc->reg_defs) < regnum)
+ while (tdesc->reg_defs.size () < regnum)
{
struct reg *reg = XCNEW (struct reg);
reg->name = "";
reg->size = 0;
- VEC_safe_push (tdesc_reg_p, tdesc->reg_defs, reg);
+ tdesc->reg_defs.push_back (reg);
}
gdb_assert (regnum == 0
- || regnum == VEC_length (tdesc_reg_p, tdesc->reg_defs));
+ || regnum == tdesc->reg_defs.size ());
struct reg *reg = XCNEW (struct reg);
reg->name = name;
reg->size = bitsize;
- VEC_safe_push (tdesc_reg_p, tdesc->reg_defs, reg);
+ tdesc->reg_defs.push_back (reg);
}
/* See arch/tdesc.h. */
diff --git a/gdb/gdbserver/tdesc.h b/gdb/gdbserver/tdesc.h
index 71249e4eda..ec4d6b38dc 100644
--- a/gdb/gdbserver/tdesc.h
+++ b/gdb/gdbserver/tdesc.h
@@ -22,9 +22,7 @@
#include "arch/tdesc.h"
#include "regdef.h"
-
-typedef struct reg *tdesc_reg_p;
-DEF_VEC_P(tdesc_reg_p);
+#include <vector>
struct tdesc_feature
{};
@@ -36,7 +34,7 @@ struct target_desc : tdesc_feature
{
/* A vector of elements of register definitions that
describe the inferior's register set. */
- VEC(tdesc_reg_p) *reg_defs;
+ std::vector<struct reg *> reg_defs;
/* The register cache size, in bytes. */
int registers_size;
@@ -66,17 +64,16 @@ struct target_desc : tdesc_feature
public:
target_desc ()
- : reg_defs (NULL), registers_size (0)
+ : registers_size (0)
{}
~target_desc ()
{
int i;
- struct reg *reg;
- for (i = 0; VEC_iterate (tdesc_reg_p, reg_defs, i, reg); i++)
+ for (reg *reg : reg_defs)
xfree (reg);
- VEC_free (tdesc_reg_p, reg_defs);
+ reg_defs.clear ();
xfree ((char *) arch);
xfree ((char *) osabi);
@@ -90,18 +87,13 @@ public:
bool operator== (const target_desc &other) const
{
- if (VEC_length (tdesc_reg_p, reg_defs)
- != VEC_length (tdesc_reg_p, other.reg_defs))
+ if (reg_defs.size () != other.reg_defs.size ())
return false;
- struct reg *reg;
-
- for (int ix = 0;
- VEC_iterate (tdesc_reg_p, reg_defs, ix, reg);
- ix++)
+ for (int i = 0; i < reg_defs.size (); ++i)
{
- struct reg *reg2
- = VEC_index (tdesc_reg_p, other.reg_defs, ix);
+ struct reg *reg = reg_defs[i];
+ struct reg *reg2 = other.reg_defs[i];
if (reg != reg2 && *reg != *reg2)
return false;
--
2.13.3
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] Use std::vector on tdesc->reg_defs (gdbserver/tdesc.h)
2017-09-10 17:12 [PATCH] Use std::vector on tdesc->reg_defs (gdbserver/tdesc.h) Sergio Durigan Junior
@ 2017-09-10 18:43 ` Simon Marchi
2017-09-10 21:35 ` Sergio Durigan Junior
2017-09-16 3:53 ` Sergio Durigan Junior
0 siblings, 2 replies; 4+ messages in thread
From: Simon Marchi @ 2017-09-10 18:43 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: GDB Patches, Yao Qi
On 2017-09-10 19:12, Sergio Durigan Junior wrote:
> This is a followup patch to the build breakage fix on AArch64. While
> doing the fix, I found it better to convert tdesc->reg_defs (on
> gdbserver/tdesc.h) from using VEC to using std::vector. This makes
> the code easier to read and maintain, and also is one more step
> towards the C++fication.
>
> Regtested on BuildBot.
Hi Sergio,
Thanks for the patch. It looks good to me, but Yao might want to look
at it since it changes an area he knows well. So leave the patch up for
a few days just in case, if you haven't heard anything new in a week,
you can push.
I just noted a nit below.
> diff --git a/gdb/gdbserver/tdesc.h b/gdb/gdbserver/tdesc.h
> index 71249e4eda..ec4d6b38dc 100644
> --- a/gdb/gdbserver/tdesc.h
> +++ b/gdb/gdbserver/tdesc.h
> @@ -22,9 +22,7 @@
> #include "arch/tdesc.h"
>
> #include "regdef.h"
> -
> -typedef struct reg *tdesc_reg_p;
> -DEF_VEC_P(tdesc_reg_p);
> +#include <vector>
>
> struct tdesc_feature
> {};
> @@ -36,7 +34,7 @@ struct target_desc : tdesc_feature
> {
> /* A vector of elements of register definitions that
> describe the inferior's register set. */
> - VEC(tdesc_reg_p) *reg_defs;
> + std::vector<struct reg *> reg_defs;
>
> /* The register cache size, in bytes. */
> int registers_size;
> @@ -66,17 +64,16 @@ struct target_desc : tdesc_feature
>
> public:
> target_desc ()
> - : reg_defs (NULL), registers_size (0)
> + : registers_size (0)
> {}
>
> ~target_desc ()
> {
> int i;
> - struct reg *reg;
>
> - for (i = 0; VEC_iterate (tdesc_reg_p, reg_defs, i, reg); i++)
> + for (reg *reg : reg_defs)
> xfree (reg);
> - VEC_free (tdesc_reg_p, reg_defs);
> + reg_defs.clear ();
The clear is unnecessary.
Thanks,
Simon
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] Use std::vector on tdesc->reg_defs (gdbserver/tdesc.h)
2017-09-10 18:43 ` Simon Marchi
@ 2017-09-10 21:35 ` Sergio Durigan Junior
2017-09-16 3:53 ` Sergio Durigan Junior
1 sibling, 0 replies; 4+ messages in thread
From: Sergio Durigan Junior @ 2017-09-10 21:35 UTC (permalink / raw)
To: Simon Marchi; +Cc: GDB Patches, Yao Qi
On Sunday, September 10 2017, Simon Marchi wrote:
> On 2017-09-10 19:12, Sergio Durigan Junior wrote:
>> This is a followup patch to the build breakage fix on AArch64. While
>> doing the fix, I found it better to convert tdesc->reg_defs (on
>> gdbserver/tdesc.h) from using VEC to using std::vector. This makes
>> the code easier to read and maintain, and also is one more step
>> towards the C++fication.
>>
>> Regtested on BuildBot.
>
> Hi Sergio,
>
> Thanks for the patch. It looks good to me, but Yao might want to look
> at it since it changes an area he knows well. So leave the patch up
> for a few days just in case, if you haven't heard anything new in a
> week, you can push.
Thanks for the review.
> I just noted a nit below.
>> diff --git a/gdb/gdbserver/tdesc.h b/gdb/gdbserver/tdesc.h
>> index 71249e4eda..ec4d6b38dc 100644
>> --- a/gdb/gdbserver/tdesc.h
>> +++ b/gdb/gdbserver/tdesc.h
>> @@ -22,9 +22,7 @@
>> #include "arch/tdesc.h"
>>
>> #include "regdef.h"
>> -
>> -typedef struct reg *tdesc_reg_p;
>> -DEF_VEC_P(tdesc_reg_p);
>> +#include <vector>
>>
>> struct tdesc_feature
>> {};
>> @@ -36,7 +34,7 @@ struct target_desc : tdesc_feature
>> {
>> /* A vector of elements of register definitions that
>> describe the inferior's register set. */
>> - VEC(tdesc_reg_p) *reg_defs;
>> + std::vector<struct reg *> reg_defs;
>>
>> /* The register cache size, in bytes. */
>> int registers_size;
>> @@ -66,17 +64,16 @@ struct target_desc : tdesc_feature
>>
>> public:
>> target_desc ()
>> - : reg_defs (NULL), registers_size (0)
>> + : registers_size (0)
>> {}
>>
>> ~target_desc ()
>> {
>> int i;
>> - struct reg *reg;
>>
>> - for (i = 0; VEC_iterate (tdesc_reg_p, reg_defs, i, reg); i++)
>> + for (reg *reg : reg_defs)
>> xfree (reg);
>> - VEC_free (tdesc_reg_p, reg_defs);
>> + reg_defs.clear ();
>
> The clear is unnecessary.
You're right, removed.
Thanks,
--
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] Use std::vector on tdesc->reg_defs (gdbserver/tdesc.h)
2017-09-10 18:43 ` Simon Marchi
2017-09-10 21:35 ` Sergio Durigan Junior
@ 2017-09-16 3:53 ` Sergio Durigan Junior
1 sibling, 0 replies; 4+ messages in thread
From: Sergio Durigan Junior @ 2017-09-16 3:53 UTC (permalink / raw)
To: Simon Marchi; +Cc: GDB Patches, Yao Qi
On Sunday, September 10 2017, Simon Marchi wrote:
> On 2017-09-10 19:12, Sergio Durigan Junior wrote:
>> This is a followup patch to the build breakage fix on AArch64. While
>> doing the fix, I found it better to convert tdesc->reg_defs (on
>> gdbserver/tdesc.h) from using VEC to using std::vector. This makes
>> the code easier to read and maintain, and also is one more step
>> towards the C++fication.
>>
>> Regtested on BuildBot.
>
> Hi Sergio,
>
> Thanks for the patch. It looks good to me, but Yao might want to look
> at it since it changes an area he knows well. So leave the patch up
> for a few days just in case, if you haven't heard anything new in a
> week, you can push.
Pushed now.
c4dfafabc575f4995a5aa18241adc275e63c846c
Thanks,
--
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-09-16 3:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-10 17:12 [PATCH] Use std::vector on tdesc->reg_defs (gdbserver/tdesc.h) Sergio Durigan Junior
2017-09-10 18:43 ` Simon Marchi
2017-09-10 21:35 ` Sergio Durigan Junior
2017-09-16 3:53 ` Sergio Durigan Junior
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox