[v2] xtensa: Properly strdup string when building reggroup
Commit Message
I noticed this while looking at the reggroup intializations. It seems
for xtensa the "cpN" reggroup->name is getting assigned to the same text
pointer for each iteration of XTENSA_MAX_COPROCESSOR.
Note 1, internally reggroup_new() does not do any xstrdup().
Note 2, I could not test this.
gdb/ChangeLog:
2017-06-10 Stafford Horne <shorne@gmail.com>
* xtensa-tdep.c (xtensa_init_reggroups): Use xstrdup for cpname.
---
Changes since v1
* Instead of using 'smart' `'0' + i` formating just use xstrprintf
* Formatting suggested by Yao
gdb/xtensa-tdep.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
Comments
Stafford Horne <shorne@gmail.com> writes:
> 2017-06-10 Stafford Horne <shorne@gmail.com>
>
> * xtensa-tdep.c (xtensa_init_reggroups): Use xstrdup for cpname.
Patch is good to me.
On Tue, Jun 13, 2017 at 02:01:35PM +0100, Yao Qi wrote:
> Stafford Horne <shorne@gmail.com> writes:
>
> > 2017-06-10 Stafford Horne <shorne@gmail.com>
> >
> > * xtensa-tdep.c (xtensa_init_reggroups): Use xstrdup for cpname.
>
> Patch is good to me.
Thanks for the review,
Sorry, I haven't been having time to follow up on my gdb patches lately.
But I will get around to them.
How will this patch get applied? I am not a maintainer yet.
-Stafford
On Thu, Aug 10, 2017 at 2:41 PM, Stafford Horne <shorne@gmail.com> wrote:
>
> How will this patch get applied? I am not a maintainer yet.
Did you get your sourceware.org account? I think
you got it. You can clone read-write git, described
in https://sourceware.org/gdb/current/
@@ -737,17 +737,13 @@ static void
xtensa_init_reggroups (void)
{
int i;
- char cpname[] = "cp0";
xtensa_ar_reggroup = reggroup_new ("ar", USER_REGGROUP);
xtensa_user_reggroup = reggroup_new ("user", USER_REGGROUP);
xtensa_vectra_reggroup = reggroup_new ("vectra", USER_REGGROUP);
for (i = 0; i < XTENSA_MAX_COPROCESSOR; i++)
- {
- cpname[2] = '0' + i;
- xtensa_cp[i] = reggroup_new (cpname, USER_REGGROUP);
- }
+ xtensa_cp[i] = reggroup_new (xstrprintf ("cp%d", i), USER_REGGROUP);
}
static void