This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 7/11] Add BFIN_MAX_REGISTER_SIZE
- From: Alan Hayward <Alan dot Hayward at arm dot com>
- To: Yao Qi <qiyaoltc at gmail dot com>
- Cc: "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>, nd <nd at arm dot com>
- Date: Fri, 7 Apr 2017 08:32:52 +0000
- Subject: Re: [PATCH 7/11] Add BFIN_MAX_REGISTER_SIZE
- Authentication-results: sourceware.org; auth=none
- Authentication-results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=arm.com;
- Nodisclaimer: True
- References: <EDDA588D-0125-4A03-AFD3-51DADFE0D4DF@arm.com> <86tw63p2rx.fsf@gmail.com> <EDE97F7B-EFCE-4B4D-B996-C458F1DC7E56@arm.com> <86d1croshn.fsf@gmail.com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
> On 5 Apr 2017, at 15:10, Yao Qi <qiyaoltc@gmail.com> wrote:
>
> Alan Hayward <Alan.Hayward@arm.com> writes:
>
>> Is it not clearer code to add and use a macro rather than a magic number ?
>>
>
> Macro is better, but "buf[4]" is not that magic, because it is only used
> within bfin_pseudo_register_read, or we can define ASTAT_REGISTER_SIZE.
>
>> It’s also not obvious anywhere that the astat register is 32bits. I had to go
>> digging inside regformats/reg-bfin.dat before I found it out.
>
> It is easier to figure out the size of a specific register than the max
> size of a set of registers.
>
>>
>> Given that BFIN_MAX_REGISTER_SIZE is also 4, it compiles to the same
>> size anyway.
>
> "gdb_byte buf[BFIN_MAX_REGISTER_SIZE]" is fine to me. Could you define
> BFIN_MAX_REGISTER_SIZE in bfin-tdep.c instead of .h? It is not used
> elsewhere.
>
Ok, pushed the following:
2017-04-07 Alan Hayward <alan.hayward@arm.com>
* bfin-tdep.c (BFIN_MAX_REGISTER_SIZE): Add.
(bfin_pseudo_register_read): Use BFIN_MAX_REGISTER_SIZE.
(bfin_pseudo_register_write): Likewise
diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
index 3df1ba387a323dc6827b1189432f8877d1833184..c590a9132c00f539b5c6e57b8f156845ff50acad 100644
--- a/gdb/bfin-tdep.c
+++ b/gdb/bfin-tdep.c
@@ -241,6 +241,8 @@ static const int map_gcc_gdb[] =
BFIN_LB1_REGNUM
};
+/* Big enough to hold the size of the largest register in bytes. */
+#define BFIN_MAX_REGISTER_SIZE 4
struct bfin_frame_cache
{
@@ -689,7 +691,7 @@ static enum register_status
bfin_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
int regnum, gdb_byte *buffer)
{
- gdb_byte *buf = (gdb_byte *) alloca (MAX_REGISTER_SIZE);
+ gdb_byte buf[BFIN_MAX_REGISTER_SIZE];
enum register_status status;
if (regnum != BFIN_CC_REGNUM)
@@ -710,7 +712,7 @@ static void
bfin_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
int regnum, const gdb_byte *buffer)
{
- gdb_byte *buf = (gdb_byte *) alloca (MAX_REGISTER_SIZE);
+ gdb_byte buf[BFIN_MAX_REGISTER_SIZE];
if (regnum != BFIN_CC_REGNUM)
internal_error (__FILE__, __LINE__,