• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Révision5e2c91a2f259140b8e45ea304a847968771024df (tree)
l'heure2006-03-24 06:49:58
AuteurDaniel Jacobowitz <drow@fals...>
CommiterDaniel Jacobowitz

Message de Log

Update g/G packet support.

Change Summary

Modification

--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -2824,8 +2824,6 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
28242824 set_gdbarch_sp_regnum (gdbarch, ARM_SP_REGNUM);
28252825 set_gdbarch_pc_regnum (gdbarch, ARM_PC_REGNUM);
28262826 set_gdbarch_num_regs (gdbarch, NUM_GREGS + NUM_FREGS + NUM_SREGS);
2827- set_gdbarch_remote_num_g_packet_regs (gdbarch,
2828- NUM_GREGS + NUM_FREGS + NUM_SREGS);
28292827 set_gdbarch_register_type (gdbarch, arm_register_type);
28302828
28312829 if (info.feature_set)
--- a/gdb/available.c
+++ b/gdb/available.c
@@ -49,12 +49,10 @@
4949 - Handle unexpected changes to _num_regs.
5050 - Call record_available_features from _gdbarch_init.
5151 - Do not override the default _register_byte
52- - Provide gdbarch_remote_num_g_packet_regs
53-*/
5452
55-/* FIXME: Everywhere we call internal_error from this file leads to a failure
56- to initialize a gdbarch, which leads to later failures when we expect
57- e.g. current_regcache to have been initialized. */
53+ (WARNING: This list is out of date and should be redone before submission.
54+ And moved into gdbint.texi.)
55+*/
5856
5957
6058
@@ -662,17 +660,20 @@ available_register_name (struct gdbarch *gdbarch, int regnum)
662660 }
663661
664662 /* Return the target-supplied register of target-described register
665- REGNUM, if the feature set for GDBARCH describes that register.
666- Otherwise return REGNUM (the legacy 1:1 mapping). */
663+ REGNUM, or -1 if the register can not be accessed. */
667664
668665 int
669666 available_register_target_regnum (struct gdbarch *gdbarch, int regnum)
670667 {
671668 struct gdb_available_register *reg;
672669
670+ /* If there is no feature set, use the legacy 1:1 mapping. */
671+ if (gdbarch_feature_set (gdbarch) == NULL)
672+ return regnum;
673+
673674 reg = find_register (gdbarch_feature_set (gdbarch), regnum);
674675 if (reg == NULL)
675- return regnum;
676+ return -1;
676677
677678 return reg->protocol_number;
678679 }
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -153,7 +153,6 @@ struct gdbarch
153153 gdbarch_pseudo_register_write_ftype *pseudo_register_write;
154154 int num_regs;
155155 int num_pseudo_regs;
156- int remote_num_g_packet_regs;
157156 int sp_regnum;
158157 int pc_regnum;
159158 int ps_regnum;
@@ -282,7 +281,6 @@ struct gdbarch startup_gdbarch =
282281 0, /* pseudo_register_write */
283282 0, /* num_regs */
284283 0, /* num_pseudo_regs */
285- 0, /* remote_num_g_packet_regs */
286284 -1, /* sp_regnum */
287285 -1, /* pc_regnum */
288286 -1, /* ps_regnum */
@@ -543,7 +541,6 @@ verify_gdbarch (struct gdbarch *current_gdbarch)
543541 if (current_gdbarch->num_regs == -1)
544542 fprintf_unfiltered (log, "\n\tnum_regs");
545543 /* Skip verify of num_pseudo_regs, invalid_p == 0 */
546- /* Skip verify of remote_num_g_packet_regs, has predicate */
547544 /* Skip verify of sp_regnum, invalid_p == 0 */
548545 /* Skip verify of pc_regnum, invalid_p == 0 */
549546 /* Skip verify of ps_regnum, invalid_p == 0 */
@@ -1489,12 +1486,6 @@ gdbarch_dump (struct gdbarch *current_gdbarch, struct ui_file *file)
14891486 "gdbarch_dump: regset_from_core_section = <0x%lx>\n",
14901487 (long) current_gdbarch->regset_from_core_section);
14911488 fprintf_unfiltered (file,
1492- "gdbarch_dump: gdbarch_remote_num_g_packet_regs_p() = %d\n",
1493- gdbarch_remote_num_g_packet_regs_p (current_gdbarch));
1494- fprintf_unfiltered (file,
1495- "gdbarch_dump: remote_num_g_packet_regs = %s\n",
1496- paddr_d (current_gdbarch->remote_num_g_packet_regs));
1497- fprintf_unfiltered (file,
14981489 "gdbarch_dump: remote_translate_xfer_address = <0x%lx>\n",
14991490 (long) current_gdbarch->remote_translate_xfer_address);
15001491 fprintf_unfiltered (file,
@@ -2099,29 +2090,6 @@ set_gdbarch_num_pseudo_regs (struct gdbarch *gdbarch,
20992090 }
21002091
21012092 int
2102-gdbarch_remote_num_g_packet_regs_p (struct gdbarch *gdbarch)
2103-{
2104- gdb_assert (gdbarch != NULL);
2105- return gdbarch->remote_num_g_packet_regs != 0;
2106-}
2107-
2108-int
2109-gdbarch_remote_num_g_packet_regs (struct gdbarch *gdbarch)
2110-{
2111- gdb_assert (gdbarch != NULL);
2112- if (gdbarch_debug >= 2)
2113- fprintf_unfiltered (gdb_stdlog, "gdbarch_remote_num_g_packet_regs called\n");
2114- return gdbarch->remote_num_g_packet_regs;
2115-}
2116-
2117-void
2118-set_gdbarch_remote_num_g_packet_regs (struct gdbarch *gdbarch,
2119- int remote_num_g_packet_regs)
2120-{
2121- gdbarch->remote_num_g_packet_regs = remote_num_g_packet_regs;
2122-}
2123-
2124-int
21252093 gdbarch_sp_regnum (struct gdbarch *gdbarch)
21262094 {
21272095 gdb_assert (gdbarch != NULL);
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -356,16 +356,6 @@ extern void set_gdbarch_num_pseudo_regs (struct gdbarch *gdbarch, int num_pseudo
356356 #define NUM_PSEUDO_REGS (gdbarch_num_pseudo_regs (current_gdbarch))
357357 #endif
358358
359-/* The number of registers fetched or stored using this target's
360- traditional g/G packet.
361- FIXME: Could we do without this by asking the target for a
362- g packet, and just seeing what's there? We surely could! */
363-
364-extern int gdbarch_remote_num_g_packet_regs_p (struct gdbarch *gdbarch);
365-
366-extern int gdbarch_remote_num_g_packet_regs (struct gdbarch *gdbarch);
367-extern void set_gdbarch_remote_num_g_packet_regs (struct gdbarch *gdbarch, int remote_num_g_packet_regs);
368-
369359 /* GDB's standard (or well known) register numbers. These can map onto
370360 a real register or a pseudo (computed) register or not be defined at
371361 all (-1).
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -433,11 +433,6 @@ v:=:int:num_regs:::0:-1
433433 # These pseudo-registers may be aliases for other registers,
434434 # combinations of other registers, or they may be computed by GDB.
435435 v:=:int:num_pseudo_regs:::0:0::0
436-# The number of registers fetched or stored using this target's
437-# traditional g/G packet.
438-# FIXME: Could we do without this by asking the target for a
439-# g packet, and just seeing what's there? We surely could!
440-V::int:remote_num_g_packet_regs
441436
442437 # GDB's standard (or well known) register numbers. These can map onto
443438 # a real register or a pseudo (computed) register or not be defined at
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -241,19 +241,26 @@ get_remote_state (void)
241241 return gdbarch_data (current_gdbarch, remote_gdbarch_data_handle);
242242 }
243243
244-static void *
245-init_remote_state (struct gdbarch *gdbarch)
244+static int
245+compare_pnums (const void *lhs_, const void *rhs_)
246246 {
247- int regnum;
248- struct remote_state *rs = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct remote_state);
249- int num_g_regs;
247+ const struct packet_reg * const *lhs = lhs_;
248+ const struct packet_reg * const *rhs = rhs_;
250249
251- if (gdbarch_remote_num_g_packet_regs_p (gdbarch))
252- num_g_regs = gdbarch_remote_num_g_packet_regs (gdbarch);
250+ if ((*lhs)->pnum < (*rhs)->pnum)
251+ return -1;
252+ else if ((*lhs)->pnum == (*rhs)->pnum)
253+ return 0;
253254 else
254- num_g_regs = NUM_REGS;
255+ return 1;
256+}
255257
256- rs->sizeof_g_packet = 0;
258+static void *
259+init_remote_state (struct gdbarch *gdbarch)
260+{
261+ int regnum, num_remote_regs, offset;
262+ struct remote_state *rs = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct remote_state);
263+ struct packet_reg **remote_regs;
257264
258265 /* Assume a 1:1 regnum<->pnum table unless the available registers
259266 interface informs us otherwise. */
@@ -263,15 +270,31 @@ init_remote_state (struct gdbarch *gdbarch)
263270 struct packet_reg *r = &rs->regs[regnum];
264271 r->pnum = available_register_target_regnum (gdbarch, regnum);
265272 r->regnum = regnum;
266- r->offset = DEPRECATED_REGISTER_BYTE (regnum);
267- r->in_g_packet = (regnum < num_g_regs);
268- /* ...name = REGISTER_NAME (regnum); */
273+ }
269274
270- /* Compute packet size by accumulating the size of all registers. */
271- if (r->in_g_packet)
272- rs->sizeof_g_packet += register_size (current_gdbarch, regnum);
275+ /* Define the g/G packet format as the contents of each register
276+ with a remote protocol number, in order of ascending protocol
277+ number. */
278+
279+ remote_regs = alloca (NUM_REGS * sizeof (struct packet_reg *));
280+ for (num_remote_regs = 0, regnum = 0; regnum < NUM_REGS; regnum++)
281+ if (rs->regs[regnum].pnum != -1)
282+ remote_regs[num_remote_regs++] = &rs->regs[regnum];
283+
284+ qsort (remote_regs, num_remote_regs, sizeof (struct packet_reg *),
285+ compare_pnums);
286+
287+ for (regnum = 0, offset = 0; regnum < num_remote_regs; regnum++)
288+ {
289+ remote_regs[regnum]->in_g_packet = 1;
290+ remote_regs[regnum]->offset = offset;
291+ offset += register_size (current_gdbarch, remote_regs[regnum]->regnum);
273292 }
274293
294+ /* Record the maximum possible size of the g packet - it may turn out
295+ to be smaller. */
296+ rs->sizeof_g_packet = offset;
297+
275298 /* Default maximum number of characters in a packet body. Many
276299 remote stubs have a hardwired buffer size of 400 bytes
277300 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
@@ -3052,6 +3075,9 @@ fetch_register_using_p (struct packet_reg *reg)
30523075 if (remote_protocol_packets[PACKET_p].support == PACKET_DISABLE)
30533076 return 0;
30543077
3078+ if (reg->pnum == -1)
3079+ return 0;
3080+
30553081 p = buf;
30563082 *p++ = 'p';
30573083 p += hexnumstr (p, reg->pnum);
@@ -3089,10 +3115,6 @@ fetch_register_using_p (struct packet_reg *reg)
30893115 return 1;
30903116 }
30913117
3092-/* Number of bytes of registers this stub implements. */
3093-
3094-static int register_bytes_found;
3095-
30963118 /* Fetch the registers included in the target's 'g' packet. */
30973119
30983120 static void
@@ -3100,20 +3122,46 @@ fetch_registers_using_g (void)
31003122 {
31013123 struct remote_state *rs = get_remote_state ();
31023124 char *buf = alloca (rs->remote_packet_size);
3103- int i;
3125+ int i, buf_len;
31043126 char *p;
3105- char *regs = alloca (rs->sizeof_g_packet);
3127+ char *regs;
31063128
31073129 set_thread (PIDGET (inferior_ptid), 1);
31083130
31093131 sprintf (buf, "g");
31103132 remote_send (buf, rs->remote_packet_size);
31113133
3112- /* Save the size of the packet sent to us by the target. Its used
3134+ buf_len = strlen (buf);
3135+
3136+ /* Sanity check the received packet. */
3137+ if (buf_len > 2 * rs->sizeof_g_packet)
3138+ error (_("remote 'g' packet reply is too large: %s"), buf);
3139+ if (buf_len % 2 != 0)
3140+ error (_("Remote 'g' packet reply is of odd length: %s"), buf);
3141+ if (REGISTER_BYTES_OK_P () && !REGISTER_BYTES_OK (i))
3142+ error (_("Remote 'g' packet reply is too short: %s"), buf);
3143+
3144+ /* Save the size of the packet sent to us by the target. It is used
31133145 as a heuristic when determining the max size of packets that the
31143146 target can safely receive. */
3115- if ((rs->actual_register_packet_size) == 0)
3116- (rs->actual_register_packet_size) = strlen (buf);
3147+ if (rs->actual_register_packet_size == 0)
3148+ rs->actual_register_packet_size = buf_len;
3149+
3150+ /* If this is smaller than we guessed the 'g' packet would be,
3151+ update our records. A 'g' reply that doesn't include a register's
3152+ value implies either that the register is not available, or that
3153+ the 'p' packet must be used. */
3154+ if (buf_len < 2 * rs->sizeof_g_packet)
3155+ {
3156+ rs->sizeof_g_packet = buf_len / 2;
3157+
3158+ for (i = 0; i < NUM_REGS; i++)
3159+ if (rs->regs[i].in_g_packet
3160+ && rs->regs[i].offset >= rs->sizeof_g_packet)
3161+ rs->regs[i].in_g_packet = 0;
3162+ }
3163+
3164+ regs = alloca (rs->sizeof_g_packet);
31173165
31183166 /* Unimplemented registers read as all bits zero. */
31193167 memset (regs, 0, rs->sizeof_g_packet);
@@ -3139,15 +3187,11 @@ fetch_registers_using_g (void)
31393187 p = buf;
31403188 for (i = 0; i < rs->sizeof_g_packet; i++)
31413189 {
3142- if (p[0] == 0)
3143- break;
3144- if (p[1] == 0)
3145- {
3146- warning (_("Remote reply is of odd length: %s"), buf);
3147- /* Don't change register_bytes_found in this case, and don't
3148- print a second warning. */
3149- goto supply_them;
3150- }
3190+ if (p[0] == 0 || p[1] == 0)
3191+ /* This shouldn't happen - we adjusted sizeof_g_packet above. */
3192+ internal_error (__FILE__, __LINE__,
3193+ "unexpected end of 'g' packet reply");
3194+
31513195 if (p[0] == 'x' && p[1] == 'x')
31523196 regs[i] = 0; /* 'x' */
31533197 else
@@ -3155,15 +3199,6 @@ fetch_registers_using_g (void)
31553199 p += 2;
31563200 }
31573201
3158- if (i != register_bytes_found)
3159- {
3160- register_bytes_found = i;
3161- if (REGISTER_BYTES_OK_P ()
3162- && !REGISTER_BYTES_OK (i))
3163- warning (_("Remote reply is too short: %s"), buf);
3164- }
3165-
3166- supply_them:
31673202 {
31683203 int i;
31693204 for (i = 0; i < NUM_REGS; i++)
@@ -3172,11 +3207,9 @@ fetch_registers_using_g (void)
31723207 if (r->in_g_packet)
31733208 {
31743209 if (r->offset * 2 >= strlen (buf))
3175- /* A short packet that didn't include the register's
3176- value, this implies that the register is zero (and
3177- not that the register is unavailable). Supply that
3178- zero value. */
3179- regcache_raw_supply (current_regcache, r->regnum, NULL);
3210+ /* This shouldn't happen - we adjusted in_g_packet above. */
3211+ internal_error (__FILE__, __LINE__,
3212+ "unexpected end of 'g' packet reply");
31803213 else if (buf[r->offset * 2] == 'x')
31813214 {
31823215 gdb_assert (r->offset * 2 < strlen (buf));
@@ -3206,14 +3239,24 @@ remote_fetch_registers (int regnum)
32063239 struct packet_reg *reg = packet_reg_from_regnum (rs, regnum);
32073240 gdb_assert (reg != NULL);
32083241
3242+ /* If this register might be in the 'g' packet, try that first -
3243+ we are likely to read more than one register. If this is the
3244+ first 'g' packet, we might be overly optimistic about its
3245+ contents, so fall back to 'p'. */
3246+ if (reg->in_g_packet)
3247+ {
3248+ fetch_registers_using_g ();
3249+ if (reg->in_g_packet)
3250+ return;
3251+ }
3252+
32093253 if (fetch_register_using_p (reg))
32103254 return;
32113255
3212- if (!reg->in_g_packet)
3213- error (_("Protocol error: register \"%s\" not supported by stub"),
3214- gdbarch_register_name (current_gdbarch, reg->regnum));
3256+ /* This register is not available. */
3257+ regcache_raw_supply (current_regcache, reg->regnum, NULL);
3258+ set_register_cached (reg->regnum, -1);
32153259
3216- fetch_registers_using_g ();
32173260 return;
32183261 }
32193262
@@ -3222,8 +3265,11 @@ remote_fetch_registers (int regnum)
32223265 for (i = 0; i < NUM_REGS; i++)
32233266 if (!rs->regs[i].in_g_packet)
32243267 if (!fetch_register_using_p (&rs->regs[i]))
3225- error (_("Protocol error: register \"%s\" not supported by stub"),
3226- gdbarch_register_name (current_gdbarch, rs->regs[i].regnum));
3268+ {
3269+ /* This register is not available. */
3270+ regcache_raw_supply (current_regcache, i, NULL);
3271+ set_register_cached (i, -1);
3272+ }
32273273 }
32283274
32293275 /* Prepare to store registers. Since we may send them all (using a
@@ -3267,6 +3313,9 @@ store_register_using_P (struct packet_reg *reg)
32673313 if (remote_protocol_packets[PACKET_P].support == PACKET_DISABLE)
32683314 return 0;
32693315
3316+ if (reg->pnum == -1)
3317+ return 0;
3318+
32703319 xsnprintf (buf, rs->remote_packet_size, "P%s=", phex_nz (reg->pnum, 0));
32713320 p = buf + strlen (buf);
32723321 regcache_raw_collect (current_regcache, reg->regnum, regp);
@@ -3317,8 +3366,9 @@ store_registers_using_G ()
33173366 buf = alloca (rs->remote_packet_size);
33183367 p = buf;
33193368 *p++ = 'G';
3320- /* remote_prepare_to_store insures that register_bytes_found gets set. */
3321- bin2hex (regs, p, register_bytes_found);
3369+ /* remote_prepare_to_store insures that rs->sizeof_g_packet gets
3370+ updated. */
3371+ bin2hex (regs, p, rs->sizeof_g_packet);
33223372 remote_send (buf, rs->remote_packet_size);
33233373 }
33243374
@@ -3338,12 +3388,19 @@ remote_store_registers (int regnum)
33383388 struct packet_reg *reg = packet_reg_from_regnum (rs, regnum);
33393389 gdb_assert (reg != NULL);
33403390
3391+ /* Always prefer to store registers using the 'P' packet if
3392+ possible; we often change only a small number of registers.
3393+ Sometimes we change a larger number; we'd need help from a
3394+ higher layer to know to use 'G'. */
33413395 if (store_register_using_P (reg))
33423396 return;
33433397
3398+ /* For now, don't complain if we have no way to write the
3399+ register. GDB loses track of unavailable registers too
3400+ easily. Some day, this may be an error. We don't have
3401+ any way to read the register, either... */
33443402 if (!reg->in_g_packet)
3345- error (_("Protocol error: register \"%s\" not supported by stub"),
3346- gdbarch_register_name (current_gdbarch, reg->regnum));
3403+ return;
33473404
33483405 store_registers_using_G ();
33493406 return;
@@ -3354,8 +3411,8 @@ remote_store_registers (int regnum)
33543411 for (i = 0; i < NUM_REGS; i++)
33553412 if (!rs->regs[i].in_g_packet)
33563413 if (!store_register_using_P (&rs->regs[i]))
3357- error (_("Protocol error: register \"%s\" not supported by stub"),
3358- gdbarch_register_name (current_gdbarch, rs->regs[i].regnum));
3414+ /* See above for why we do not issue an error here. */
3415+ continue;
33593416 }
33603417
33613418