From patchwork Mon Feb 6 09:33:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 19120 Received: (qmail 64948 invoked by alias); 6 Feb 2017 09:33:43 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 64921 invoked by uid 89); 6 Feb 2017 09:33:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.2 required=5.0 tests=AWL, BAYES_40, KAM_LOTSOFHASH, MIME_BASE64_BLANKS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=no version=3.3.2 spammy=2028, 1876, sk:alanha, sk:alan.ha X-HELO: EUR02-HE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr10051.outbound.protection.outlook.com (HELO EUR02-HE1-obe.outbound.protection.outlook.com) (40.107.1.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 06 Feb 2017 09:33:32 +0000 Received: from VI1PR0801MB1822.eurprd08.prod.outlook.com (10.168.68.7) by VI1PR0801MB1821.eurprd08.prod.outlook.com (10.168.67.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.888.16; Mon, 6 Feb 2017 09:33:25 +0000 Received: from VI1PR0801MB1822.eurprd08.prod.outlook.com ([10.168.68.7]) by VI1PR0801MB1822.eurprd08.prod.outlook.com ([10.168.68.7]) with mapi id 15.01.0888.022; Mon, 6 Feb 2017 09:33:25 +0000 From: Alan Hayward To: Yao Qi CC: Pedro Alves , Joel Brobecker , "gdb-patches@sourceware.org" , nd Subject: Re: [PATCH] Removal of uses of MAX_REGISTER_SIZE Date: Mon, 6 Feb 2017 09:33:25 +0000 Message-ID: <1E0030CE-FB37-4821-AA53-9C6D1CC285C9@arm.com> References: <7CF07197-4FED-4970-BB4B-2FE828E29A63@arm.com> <45e3a5e1-a9aa-1bc0-5d08-526b89fc458e@redhat.com> <20170201124123.GA27498@E107787-LIN> <20170202094012.dge4r6rsl2skdrii@adacore.com> <20170203102819.GA11916@E107787-LIN> <25716edf-096e-20c5-4170-fb8ca04d897b@redhat.com> <0C6A0D51-4C49-4400-8C46-E77DD512DF56@arm.com> <20170203165022.GB11916@E107787-LIN> In-Reply-To: <20170203165022.GB11916@E107787-LIN> authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-office365-filtering-correlation-id: fd9efeb3-9df8-476f-645f-08d44e733380 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:VI1PR0801MB1821; x-microsoft-exchange-diagnostics: 1; VI1PR0801MB1821; 7:uxUztJJFSnSiF0wXnmhgeCLeC2rYpcLLFh8gaoYv9gKwcqmH85nukMvx2rvO39bRo+qmA/y/k0NBEamV88+aYlXPH88WkRAiKCEwjItopdiQq3eKpotDZqeOPkVZjN9uH5N/8wQzu3LCbIA8Fk4aMO+R8JVG77dUoZNZYCYum5AHz9bex8lJANO99k66zcvGObQCsC/DHJmKgOe3nxUKHirH3xmh2V0Mt1s9XgqT2NCPveHHySDEr9VoOajVe2c/RpAaIwIL/qDCD23nyB2s+DHZDCxagckuTViYya8AJ9YGFXU1/hZ3Mh3xMKPxUV/Ods9pxGS1RYl6+2WrsYzVIf1LaSOfWv/+WZpBpfqt9pQJ6AnhvhrIiWTq3NbmUzJJ1sC7OS9XMdAvPxOa3aTr4dKA2tLDqkgFZTDRuy37TG2EYphoD3lB9GjQy2bojQdL6NQCrtqKd3xwmHCCgXG15+VxynK4bdgHMHqSyZ0unca2pmqqkFCXCai6YwU3HIaehx0kEfQ+ox+qE6N+Egb0hQ== nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(20170203043)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6041248)(20161123555025)(20161123558025)(20161123564025)(20161123560025)(20161123562025)(6072148); SRVR:VI1PR0801MB1821; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0801MB1821; x-forefront-prvs: 0210479ED8 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(7916002)(39840400002)(39410400002)(39450400003)(39850400002)(377424004)(24454002)(189002)(199003)(51444003)(3846002)(6116002)(102836003)(83716003)(2900100001)(189998001)(36756003)(7736002)(68736007)(305945005)(33656002)(3280700002)(97736004)(3660700001)(8676002)(81156014)(81166006)(106116001)(6512007)(122556002)(92566002)(8936002)(110136003)(2950100002)(6506006)(106356001)(105586002)(82746002)(6916009)(6436002)(2906002)(25786008)(54906002)(99286003)(5660300001)(86362001)(6246003)(53936002)(39060400001)(38730400001)(6486002)(101416001)(53546003)(76176999)(575784001)(53946003)(77096006)(93886004)(66066001)(229853002)(1411001)(54356999)(4326007)(50986999)(104396002)(559001)(579004); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0801MB1821; H:VI1PR0801MB1822.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <256267985BD1C84597F2659CDB6F11B6@eurprd08.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Feb 2017 09:33:25.6699 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1821 > On 3 Feb 2017, at 16:50, Yao Qi wrote: > > On 17-02-03 11:25:43, Alan Hayward wrote: >> If someone can ok the common patch, then I’ll make a second patch with the >> replacement of all remaining uses of MAX_REGISTER_SIZE in common code. > > I'd like to do it in an iterative way, start from some simple places, like > arm, aarch64, and i386, in which you don't need to define new macros. Then, > move to some *-tdep.c and *-nat.c, define ${ARCH}_MAX_REGISTER_SIZE when > necessary. Finally, figure out how to remove MAX_REGISTER_SIZE from > arch-independent code. > >> Ensuring it’s not used in common code will allow me to continue moving with the >> aarch64 SVE code. >> >> >> There are quite a lot of arch specific functions where we have a register number >> from which the register size could be extracted. Eg: >> >> void >> SOMEARCH_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, >> int regnum, const gdb_byte *buf) >> { >> gdb_byte raw_buf[MAX_REGISTER_SIZE]; >> >> >> This could become: >> >> void >> SOMEARCH_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, >> int regnum, const gdb_byte *buf) >> { >> gdb_byte buf[SOMEARCH_MAX_REGISTER_SIZE]; >> >> >> Or: >> >> void >> SOMEARCH_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, >> int regnum, const gdb_byte *buf) >> { >> std::vector buf (register_size (gdbarch, regnum)); >> >> >> I suspect people will want the first approach? It will result in quite a few new >> defines - ALPHA_MAX_REGISTER_SIZE, PPC_MAX_REGISTER_SIZE etc etc. >> > > That is fine, we've already had I386_MAX_REGISTER_SIZE and M68K_MAX_REGISTER_SIZE. > However, I think that we only have to add these macros when necessary. > > > -- > Yao (齐尧) Ok, Given that, I've put together a quick patch to: * Use M68K_MAX_REGISTER_SIZE and I386_MAX_REGISTER_SIZE where possible. * Add max_register_size() function * Remove MAX_REGISTER_SIZE from all common files by using std::vector. Contents should be very similar to previous patches posted. This patch ok? 2017-02-06 Alan Hayward * frame.c (frame_unwind_register_signed): Use std::vector. (frame_unwind_register_unsigned): Likewise. (get_frame_register_bytes): Likewise. (put_frame_register_bytes): Likewise. * i386-tdep.c (i386_pseudo_register_read_into_value): Use I386_MAX_REGISTER_SIZE. (i386_pseudo_register_write): Likewise. (i386_process_record): Likewise. * i387-tdep.c (i387_supply_xsave): Likewise. * m68k-linux-nat.c (fetch_register): Use M68K_MAX_REGISTER_SIZE. (store_register): Likewise. * mi/mi-main.c (register_changed_p): Use std::vector. * record-full.c (record_full_exec_insn): Likewise. (record_full_core_open_1): Use max_register_size (). (record_full_core_fetch_registers): Likewise. (record_full_core_store_registers): Likewise. (init_record_full_core_ops): Likewise. * remote-sim.c (gdbsim_fetch_register): Likewise. (gdbsim_store_register): Likewise. * regcache.c (struct regcache_descr): Add max_register_size. (max_register_size): New. (init_regcache_descr): Find max register size. (regcache_save): Use std::vector. (regcache_restore): Likewise. (regcache_dump): Likewise. * regcache.h (max_register_size): New. * remote.c (remote_prepare_to_store): Use std::vector. * sol-thread.c (sol_thread_store_registers): Likewise. * stack.c (frame_info): Likewise. * target.c (debug_print_register): Likewise. diff --git a/gdb/frame.c b/gdb/frame.c index d98003dee7c34a63bd25356e6674721664a4b2f3..1700308371d9d795545c0a8bb26dba289b18217d 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -1252,10 +1252,10 @@ frame_unwind_register_signed (struct frame_info *frame, int regnum) struct gdbarch *gdbarch = frame_unwind_arch (frame); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); int size = register_size (gdbarch, regnum); - gdb_byte buf[MAX_REGISTER_SIZE]; + std::vector buf (size); - frame_unwind_register (frame, regnum, buf); - return extract_signed_integer (buf, size, byte_order); + frame_unwind_register (frame, regnum, buf.data ()); + return extract_signed_integer (buf.data (), size, byte_order); } LONGEST @@ -1270,10 +1270,10 @@ frame_unwind_register_unsigned (struct frame_info *frame, int regnum) struct gdbarch *gdbarch = frame_unwind_arch (frame); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); int size = register_size (gdbarch, regnum); - gdb_byte buf[MAX_REGISTER_SIZE]; + std::vector buf (size); - frame_unwind_register (frame, regnum, buf); - return extract_unsigned_integer (buf, size, byte_order); + frame_unwind_register (frame, regnum, buf.data ()); + return extract_unsigned_integer (buf.data (), size, byte_order); } ULONGEST @@ -1389,6 +1389,8 @@ get_frame_register_bytes (struct frame_info *frame, int regnum, error (_("Bad debug information detected: " "Attempt to read %d bytes from registers."), len); + std::vector buf (max_register_size (gdbarch)); + /* Copy the data. */ while (len > 0) { @@ -1410,16 +1412,15 @@ get_frame_register_bytes (struct frame_info *frame, int regnum, } else { - gdb_byte buf[MAX_REGISTER_SIZE]; enum lval_type lval; CORE_ADDR addr; int realnum; frame_register (frame, regnum, optimizedp, unavailablep, - &lval, &addr, &realnum, buf); + &lval, &addr, &realnum, buf.data ()); if (*optimizedp || *unavailablep) return 0; - memcpy (myaddr, buf + offset, curr_len); + memcpy (myaddr, buf.data () + offset, curr_len); } myaddr += curr_len; @@ -1446,6 +1447,8 @@ put_frame_register_bytes (struct frame_info *frame, int regnum, regnum++; } + std::vector buf (max_register_size (gdbarch)); + /* Copy the data. */ while (len > 0) { @@ -1460,11 +1463,9 @@ put_frame_register_bytes (struct frame_info *frame, int regnum, } else { - gdb_byte buf[MAX_REGISTER_SIZE]; - - deprecated_frame_register_read (frame, regnum, buf); - memcpy (buf + offset, myaddr, curr_len); - put_frame_register (frame, regnum, buf); + deprecated_frame_register_read (frame, regnum, buf.data ()); + memcpy (buf.data () + offset, myaddr, curr_len); + put_frame_register (frame, regnum, buf.data ()); } myaddr += curr_len; diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index 8a4d59f6fdae8ec785462d0ceedcd6501b955cf0..081a16c6896ce7aee4db3b0be45fbbdd2c23dbdb 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -3250,7 +3250,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch, int regnum, struct value *result_value) { - gdb_byte raw_buf[MAX_REGISTER_SIZE]; + gdb_byte raw_buf[I386_MAX_REGISTER_SIZE]; enum register_status status; gdb_byte *buf = value_contents_raw (result_value); @@ -3455,7 +3455,7 @@ void i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, int regnum, const gdb_byte *buf) { - gdb_byte raw_buf[MAX_REGISTER_SIZE]; + gdb_byte raw_buf[I386_MAX_REGISTER_SIZE]; if (i386_mmx_regnum_p (gdbarch, regnum)) { @@ -5037,7 +5037,7 @@ i386_process_record (struct gdbarch *gdbarch, struct regcache *regcache, uint32_t opcode; uint8_t opcode8; ULONGEST addr; - gdb_byte buf[MAX_REGISTER_SIZE]; + gdb_byte buf[I386_MAX_REGISTER_SIZE]; struct i386_record_s ir; struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); uint8_t rex_w = -1; diff --git a/gdb/i387-tdep.c b/gdb/i387-tdep.c index adbe72133089bc371108d5dd79bf8d8e61ba259c..fcd5ad248d6b737b9f27e294ce166a118e4bdcad 100644 --- a/gdb/i387-tdep.c +++ b/gdb/i387-tdep.c @@ -899,7 +899,7 @@ i387_supply_xsave (struct regcache *regcache, int regnum, const gdb_byte *regs = (const gdb_byte *) xsave; int i; unsigned int clear_bv; - static const gdb_byte zero[MAX_REGISTER_SIZE] = { 0 }; + static const gdb_byte zero[I386_MAX_REGISTER_SIZE] = { 0 }; enum { none = 0x0, diff --git a/gdb/m68k-linux-nat.c b/gdb/m68k-linux-nat.c index 6944c74eb198381135fda3ddf01b9da3a63e62d5..e5182caf39197f759c85c2321e4d66c428f5911e 100644 --- a/gdb/m68k-linux-nat.c +++ b/gdb/m68k-linux-nat.c @@ -105,7 +105,7 @@ fetch_register (struct regcache *regcache, int regno) struct gdbarch *gdbarch = get_regcache_arch (regcache); long regaddr, val; int i; - gdb_byte buf[MAX_REGISTER_SIZE]; + gdb_byte buf[M68K_MAX_REGISTER_SIZE]; int tid; /* Overload thread id onto process id. */ @@ -160,7 +160,7 @@ store_register (const struct regcache *regcache, int regno) long regaddr, val; int i; int tid; - gdb_byte buf[MAX_REGISTER_SIZE]; + gdb_byte buf[M68K_MAX_REGISTER_SIZE]; /* Overload thread id onto process id. */ tid = ptid_get_lwp (inferior_ptid); diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 57c23ebf5d6b2d3b398aa40ebd9b3cb70c56125c..b07335d82723f3ee9c7602a8fa284acb7e3b3a25 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -1135,8 +1135,8 @@ register_changed_p (int regnum, struct regcache *prev_regs, struct regcache *this_regs) { struct gdbarch *gdbarch = get_regcache_arch (this_regs); - gdb_byte prev_buffer[MAX_REGISTER_SIZE]; - gdb_byte this_buffer[MAX_REGISTER_SIZE]; + std::vector prev_buffer (max_register_size (gdbarch)); + std::vector this_buffer (max_register_size (gdbarch)); enum register_status prev_status; enum register_status this_status; @@ -1146,13 +1146,13 @@ register_changed_p (int regnum, struct regcache *prev_regs, return 1; /* Get register contents and compare. */ - prev_status = regcache_cooked_read (prev_regs, regnum, prev_buffer); - this_status = regcache_cooked_read (this_regs, regnum, this_buffer); + prev_status = regcache_cooked_read (prev_regs, regnum, prev_buffer.data ()); + this_status = regcache_cooked_read (this_regs, regnum, this_buffer.data ()); if (this_status != prev_status) return 1; else if (this_status == REG_VALID) - return memcmp (prev_buffer, this_buffer, + return memcmp (prev_buffer.data (), this_buffer.data (), register_size (gdbarch, regnum)) != 0; else return 0; diff --git a/gdb/record-full.c b/gdb/record-full.c index fdd613b6e41bbfcd8644b02ccfeb98b53b518bff..a619e09a646c48c632a60407d7018979d805a08f 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -698,7 +698,7 @@ record_full_exec_insn (struct regcache *regcache, { case record_full_reg: /* reg */ { - gdb_byte reg[MAX_REGISTER_SIZE]; + std::vector reg (register_size (gdbarch, entry->u.reg.num)); if (record_debug > 1) fprintf_unfiltered (gdb_stdlog, @@ -707,10 +707,10 @@ record_full_exec_insn (struct regcache *regcache, host_address_to_string (entry), entry->u.reg.num); - regcache_cooked_read (regcache, entry->u.reg.num, reg); - regcache_cooked_write (regcache, entry->u.reg.num, + regcache_cooked_read (regcache, entry->u.reg.num, reg.data ()); + regcache_cooked_write (regcache, entry->u.reg.num, record_full_get_loc (entry)); - memcpy (record_full_get_loc (entry), reg, entry->u.reg.len); + memcpy (record_full_get_loc (entry), reg.data (), entry->u.reg.len); } break; @@ -792,15 +792,17 @@ static void record_full_core_open_1 (const char *name, int from_tty) { struct regcache *regcache = get_current_regcache (); - int regnum = gdbarch_num_regs (get_regcache_arch (regcache)); + struct gdbarch *gdbarch = get_regcache_arch (regcache); + int regnum = gdbarch_num_regs (gdbarch); + int regmaxsize = max_register_size (gdbarch); int i; /* Get record_full_core_regbuf. */ target_fetch_registers (regcache, -1); - record_full_core_regbuf = (gdb_byte *) xmalloc (MAX_REGISTER_SIZE * regnum); + record_full_core_regbuf = (gdb_byte *) xmalloc (regmaxsize * regnum); for (i = 0; i < regnum; i ++) regcache_raw_collect (regcache, i, - record_full_core_regbuf + MAX_REGISTER_SIZE * i); + record_full_core_regbuf + regmaxsize * i); /* Get record_full_core_start and record_full_core_end. */ if (build_section_table (core_bfd, &record_full_core_start, @@ -2038,6 +2040,9 @@ record_full_core_fetch_registers (struct target_ops *ops, struct regcache *regcache, int regno) { + struct gdbarch *gdbarch = get_regcache_arch (regcache); + int regmaxsize = max_register_size (gdbarch); + if (regno < 0) { int num = gdbarch_num_regs (get_regcache_arch (regcache)); @@ -2045,11 +2050,11 @@ record_full_core_fetch_registers (struct target_ops *ops, for (i = 0; i < num; i ++) regcache_raw_supply (regcache, i, - record_full_core_regbuf + MAX_REGISTER_SIZE * i); + record_full_core_regbuf + regmaxsize * i); } else regcache_raw_supply (regcache, regno, - record_full_core_regbuf + MAX_REGISTER_SIZE * regno); + record_full_core_regbuf + regmaxsize * regno); } /* "to_prepare_to_store" method for prec over corefile. */ @@ -2067,9 +2072,12 @@ record_full_core_store_registers (struct target_ops *ops, struct regcache *regcache, int regno) { + struct gdbarch *gdbarch = get_regcache_arch (regcache); + int regmaxsize = max_register_size (gdbarch); + if (record_full_gdb_operation_disable) regcache_raw_collect (regcache, regno, - record_full_core_regbuf + MAX_REGISTER_SIZE * regno); + record_full_core_regbuf + regmaxsize * regno); else error (_("You can't do that without a process to debug.")); } @@ -2265,7 +2273,7 @@ init_record_full_core_ops (void) record_full_reg: 1 byte: record type (record_full_reg, see enum record_full_type). 8 bytes: register id (network byte order). - MAX_REGISTER_SIZE bytes: register value. + max_register_size bytes: register value. record_full_mem: 1 byte: record type (record_full_mem, see enum record_full_type). 8 bytes: memory length (network byte order). diff --git a/gdb/regcache.h b/gdb/regcache.h index e5a7cf553279b8cc0d546ec1b8274cbf97e246d5..5bc99f5c1ef87318edf4e934ec60c7f1225e7561 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -202,6 +202,8 @@ extern struct type *register_type (struct gdbarch *gdbarch, int regnum); extern int register_size (struct gdbarch *gdbarch, int regnum); +/* Return the size of the largest register. */ +extern long max_register_size (struct gdbarch *gdbarch); /* Save/restore a register cache. The set of registers saved / restored into the DST regcache determined by the save_reggroup / diff --git a/gdb/regcache.c b/gdb/regcache.c index 9d28aa2c2114e0f1c52758bb2fbe9669a329c13e..522633ae0fdf6d80508d725bc1d68d05567fd9ff 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -73,6 +73,9 @@ struct regcache_descr /* Cached table containing the type of each register. */ struct type **register_type; + + /* Size of the largest register. */ + long max_register_size; }; static void * @@ -126,6 +129,8 @@ init_regcache_descr (struct gdbarch *gdbarch) descr->register_offset[i] = offset; offset += descr->sizeof_register[i]; gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]); + descr->max_register_size = std::max (descr->max_register_size, + descr->sizeof_register[i]); } /* Set the real size of the raw register cache buffer. */ descr->sizeof_raw_registers = offset; @@ -136,6 +141,8 @@ init_regcache_descr (struct gdbarch *gdbarch) descr->register_offset[i] = offset; offset += descr->sizeof_register[i]; gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]); + descr->max_register_size = std::max (descr->max_register_size, + descr->sizeof_register[i]); } /* Set the real size of the readonly register cache buffer. */ descr->sizeof_cooked_registers = offset; @@ -187,6 +194,13 @@ regcache_register_size (const struct regcache *regcache, int n) return register_size (get_regcache_arch (regcache), n); } +long +max_register_size (struct gdbarch *gdbarch) +{ + struct regcache_descr *descr = regcache_descr (gdbarch); + return descr->max_register_size; +} + /* The register cache for storing raw register values. */ struct regcache @@ -327,7 +341,7 @@ regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read, void *src) { struct gdbarch *gdbarch = dst->descr->gdbarch; - gdb_byte buf[MAX_REGISTER_SIZE]; + std::vector buf (max_register_size (gdbarch)); int regnum; /* The DST should be `read-only', if it wasn't then the save would @@ -346,10 +360,10 @@ regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read, { if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup)) { - enum register_status status = cooked_read (src, regnum, buf); + enum register_status status = cooked_read (src, regnum, buf.data ()); if (status == REG_VALID) - memcpy (register_buffer (dst, regnum), buf, + memcpy (register_buffer (dst, regnum), buf.data (), register_size (gdbarch, regnum)); else { @@ -369,7 +383,7 @@ regcache_restore (struct regcache *dst, void *cooked_read_context) { struct gdbarch *gdbarch = dst->descr->gdbarch; - gdb_byte buf[MAX_REGISTER_SIZE]; + std::vector buf (max_register_size (gdbarch)); int regnum; /* The dst had better not be read-only. If it is, the `restore' @@ -385,9 +399,9 @@ regcache_restore (struct regcache *dst, { enum register_status status; - status = cooked_read (cooked_read_context, regnum, buf); + status = cooked_read (cooked_read_context, regnum, buf.data ()); if (status == REG_VALID) - regcache_cooked_write (dst, regnum, buf); + regcache_cooked_write (dst, regnum, buf.data ()); } } } @@ -1279,7 +1293,7 @@ regcache_dump (struct regcache *regcache, struct ui_file *file, int footnote_register_offset = 0; int footnote_register_type_name_null = 0; long register_offset = 0; - gdb_byte buf[MAX_REGISTER_SIZE]; + std::vector buf (max_register_size (gdbarch)); #if 0 fprintf_unfiltered (file, "nr_raw_registers %d\n", @@ -1406,8 +1420,8 @@ regcache_dump (struct regcache *regcache, struct ui_file *file, fprintf_unfiltered (file, ""); else { - regcache_raw_read (regcache, regnum, buf); - print_hex_chars (file, buf, + regcache_raw_read (regcache, regnum, buf.data ()); + print_hex_chars (file, buf.data (), regcache->descr->sizeof_register[regnum], gdbarch_byte_order (gdbarch)); } @@ -1422,13 +1436,13 @@ regcache_dump (struct regcache *regcache, struct ui_file *file, { enum register_status status; - status = regcache_cooked_read (regcache, regnum, buf); + status = regcache_cooked_read (regcache, regnum, buf.data ()); if (status == REG_UNKNOWN) fprintf_unfiltered (file, ""); else if (status == REG_UNAVAILABLE) fprintf_unfiltered (file, ""); else - print_hex_chars (file, buf, + print_hex_chars (file, buf.data (), regcache->descr->sizeof_register[regnum], gdbarch_byte_order (gdbarch)); } diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c index b0c68c617e365c0ea18ac2eca525598b688ffbb5..c5b1a480c52e12af01dc2d6c959fd429735bc805 100644 --- a/gdb/remote-sim.c +++ b/gdb/remote-sim.c @@ -439,6 +439,9 @@ gdbsim_fetch_register (struct target_ops *ops, return; } + int regsize = register_size (gdbarch, regno); + std::vector buf (regsize); + switch (gdbarch_register_sim_regno (gdbarch, regno)) { case LEGACY_SIM_REGNO_IGNORE: @@ -447,10 +450,9 @@ gdbsim_fetch_register (struct target_ops *ops, { /* For moment treat a `does not exist' register the same way as an ``unavailable'' register. */ - gdb_byte buf[MAX_REGISTER_SIZE]; int nr_bytes; - memset (buf, 0, MAX_REGISTER_SIZE); + memset (buf, 0, regsize); regcache_raw_supply (regcache, regno, buf); break; } @@ -458,18 +460,17 @@ gdbsim_fetch_register (struct target_ops *ops, default: { static int warn_user = 1; - gdb_byte buf[MAX_REGISTER_SIZE]; int nr_bytes; gdb_assert (regno >= 0 && regno < gdbarch_num_regs (gdbarch)); - memset (buf, 0, MAX_REGISTER_SIZE); + memset (buf, 0, regsize); nr_bytes = sim_fetch_register (sim_data->gdbsim_desc, gdbarch_register_sim_regno (gdbarch, regno), buf, - register_size (gdbarch, regno)); + regsize); if (nr_bytes > 0 - && nr_bytes != register_size (gdbarch, regno) && warn_user) + && nr_bytes != regsize && warn_user) { fprintf_unfiltered (gdb_stderr, "Size of register %s (%d/%d) " @@ -478,7 +479,7 @@ gdbsim_fetch_register (struct target_ops *ops, regno, gdbarch_register_sim_regno (gdbarch, regno), - nr_bytes, register_size (gdbarch, regno)); + nr_bytes, regsize); warn_user = 0; } /* FIXME: cagney/2002-05-27: Should check `nr_bytes == 0' @@ -492,7 +493,7 @@ gdbsim_fetch_register (struct target_ops *ops, fprintf_unfiltered (gdb_stdlog, "gdbsim_fetch_register: %d", regno); /* FIXME: We could print something more intelligible. */ - dump_mem (buf, register_size (gdbarch, regno)); + dump_mem (buf, regsize); } break; } @@ -516,15 +517,16 @@ gdbsim_store_register (struct target_ops *ops, } else if (gdbarch_register_sim_regno (gdbarch, regno) >= 0) { - gdb_byte tmp[MAX_REGISTER_SIZE]; + int regsize = register_size (gdbarch, regno); + std::vector tmp (regsize); int nr_bytes; regcache_cooked_read (regcache, regno, tmp); nr_bytes = sim_store_register (sim_data->gdbsim_desc, gdbarch_register_sim_regno (gdbarch, regno), - tmp, register_size (gdbarch, regno)); - if (nr_bytes > 0 && nr_bytes != register_size (gdbarch, regno)) + tmp, regsize); + if (nr_bytes > 0 && nr_bytes != regsize) internal_error (__FILE__, __LINE__, _("Register size different to expected")); if (nr_bytes < 0) @@ -538,7 +540,7 @@ gdbsim_store_register (struct target_ops *ops, { fprintf_unfiltered (gdb_stdlog, "gdbsim_store_register: %d", regno); /* FIXME: We could print something more intelligible. */ - dump_mem (tmp, register_size (gdbarch, regno)); + dump_mem (tmp, regsize); } } } diff --git a/gdb/remote.c b/gdb/remote.c index c4cec910c44cf91cc7f36b7f2d87cde3f46de41e..157a1b1789d2a248c11dcc4efebd8ce54da82045 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -7757,9 +7757,10 @@ remote_fetch_registers (struct target_ops *ops, static void remote_prepare_to_store (struct target_ops *self, struct regcache *regcache) { + struct gdbarch *gdbarch = get_regcache_arch (regcache); struct remote_arch_state *rsa = get_remote_arch_state (); int i; - gdb_byte buf[MAX_REGISTER_SIZE]; + std::vector buf (max_register_size (gdbarch)); /* Make sure the entire registers array is valid. */ switch (packet_support (PACKET_P)) @@ -7769,7 +7770,7 @@ remote_prepare_to_store (struct target_ops *self, struct regcache *regcache) /* Make sure all the necessary registers are cached. */ for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++) if (rsa->regs[i].in_g_packet) - regcache_raw_read (regcache, rsa->regs[i].regnum, buf); + regcache_raw_read (regcache, rsa->regs[i].regnum, buf.data ()); break; case PACKET_ENABLE: break; diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c index a09a3ab9a8bc56f367e3ba1537f5674f0a7f491f..5e7443a97624fbeae5b65cb534401e6371755423 100644 --- a/gdb/sol-thread.c +++ b/gdb/sol-thread.c @@ -514,6 +514,7 @@ sol_thread_store_registers (struct target_ops *ops, td_err_e val; prgregset_t gregset; prfpregset_t fpregset; + struct gdbarch *gdbarch = get_regcache_arch (regcache); if (!ptid_tid_p (inferior_ptid)) { @@ -535,10 +536,10 @@ sol_thread_store_registers (struct target_ops *ops, if (regnum != -1) { /* Not writing all the registers. */ - char old_value[MAX_REGISTER_SIZE]; + std::vector old_value (register_size (gdbarch, regnum)); /* Save new register value. */ - regcache_raw_collect (regcache, regnum, old_value); + regcache_raw_collect (regcache, regnum, old_value.data ()); val = p_td_thr_getgregs (&thandle, gregset); if (val != TD_OK) @@ -550,7 +551,7 @@ sol_thread_store_registers (struct target_ops *ops, td_err_string (val)); /* Restore new register value. */ - regcache_raw_supply (regcache, regnum, old_value); + regcache_raw_supply (regcache, regnum, old_value.data ()); } fill_gregset (regcache, (gdb_gregset_t *) &gregset, regnum); diff --git a/gdb/stack.c b/gdb/stack.c index e00e2972cf20bc63917af19f86bf57f1c6b0b5b0..9b84435fe73b9af9b13f01c819f77f83bbb7117b 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -1667,16 +1667,16 @@ frame_info (char *addr_exp, int from_tty) { enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); int sp_size = register_size (gdbarch, gdbarch_sp_regnum (gdbarch)); - gdb_byte value[MAX_REGISTER_SIZE]; + std::vector value (sp_size); CORE_ADDR sp; frame_register_unwind (fi, gdbarch_sp_regnum (gdbarch), &optimized, &unavailable, &lval, &addr, - &realnum, value); + &realnum, value.data ()); /* NOTE: cagney/2003-05-22: This is assuming that the stack pointer was packed as an unsigned integer. That may or may not be valid. */ - sp = extract_unsigned_integer (value, sp_size, byte_order); + sp = extract_unsigned_integer (value.data (), sp_size, byte_order); printf_filtered (" Previous frame's sp is "); fputs_filtered (paddress (gdbarch, sp), gdb_stdout); printf_filtered ("\n"); diff --git a/gdb/target.c b/gdb/target.c index 3c409f0f619141205dfdcbbf8e46a277585ed683..52bb59255fcbdc74a674e08f6e168be5b6294819 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -3565,17 +3565,18 @@ debug_print_register (const char * func, { enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); int i, size = register_size (gdbarch, regno); - gdb_byte buf[MAX_REGISTER_SIZE]; + std::vector buf (size); - regcache_raw_collect (regcache, regno, buf); + regcache_raw_collect (regcache, regno, buf.data ()); fprintf_unfiltered (gdb_stdlog, " = "); for (i = 0; i < size; i++) { - fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]); + fprintf_unfiltered (gdb_stdlog, "%02x", buf.data ()[i]); } if (size <= sizeof (LONGEST)) { - ULONGEST val = extract_unsigned_integer (buf, size, byte_order); + ULONGEST val = extract_unsigned_integer (buf.data (), size, + byte_order); fprintf_unfiltered (gdb_stdlog, " %s %s", core_addr_to_string_nz (val), plongest (val));