Skip to content

Commit 9c1f84c

Browse files
committed
[gdbsupport] Reimplement phex and phex_nz as templates
Gdbsupport functions phex and phex_nz have a parameter sizeof_l: ... extern const char *phex (ULONGEST l, int sizeof_l); extern const char *phex_nz (ULONGEST l, int sizeof_l); ... and a lot of calls use: ... phex (l, sizeof (l)) ... Make this easier by reimplementing the functions as a template, allowing us to simply write: ... phex (l) ... Simplify existing code using: ... $ find gdb* -type f \ | xargs sed -i 's/phex (\([^,]*\), sizeof (\1))/phex (\1)/' $ find gdb* -type f \ | xargs sed -i 's/phex_nz (\([^,]*\), sizeof (\1))/phex_nz (\1)/' ... and manually review: ... $ find gdb* -type f | xargs grep "phex (.*, sizeof.*)" $ find gdb* -type f | xargs grep "phex_nz (.*, sizeof.*)" ... Tested on x86_64-linux. Approved-By: Tom Tromey <[email protected]>
1 parent a048980 commit 9c1f84c

16 files changed

+68
-48
lines changed

gdb/aarch64-linux-tdep.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,8 +2599,8 @@ aarch64_linux_fill_memtag_section (struct gdbarch *gdbarch, asection *osec)
25992599
static_cast<int> (memtag_type::allocation)))
26002600
{
26012601
warning (_("Failed to read MTE tags from memory range [%s,%s)."),
2602-
phex_nz (start_address, sizeof (start_address)),
2603-
phex_nz (end_address, sizeof (end_address)));
2602+
phex_nz (start_address),
2603+
phex_nz (end_address));
26042604
return false;
26052605
}
26062606

gdb/aarch64-tdep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4236,7 +4236,7 @@ aarch64_memtag_to_string (struct gdbarch *gdbarch, struct value *tag_value)
42364236

42374237
CORE_ADDR tag = value_as_address (tag_value);
42384238

4239-
return string_printf ("0x%s", phex_nz (tag, sizeof (tag)));
4239+
return string_printf ("0x%s", phex_nz (tag));
42404240
}
42414241

42424242
/* See aarch64-tdep.h. */

gdb/breakpoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10289,7 +10289,7 @@ masked_watchpoint::print_recreate (struct ui_file *fp) const
1028910289
}
1029010290

1029110291
gdb_printf (fp, " %s mask 0x%s", exp_string.get (),
10292-
phex (hw_wp_mask, sizeof (CORE_ADDR)));
10292+
phex (hw_wp_mask));
1029310293
print_recreate_thread (fp);
1029410294
}
1029510295

gdb/bsd-uthread.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ bsd_uthread_target::pid_to_str (ptid_t ptid)
536536
if (ptid.tid () != 0)
537537
return string_printf ("process %d, thread 0x%s",
538538
ptid.pid (),
539-
phex_nz (ptid.tid (), sizeof (ULONGEST)));
539+
phex_nz (ptid.tid ()));
540540

541541
return normal_pid_to_str (ptid);
542542
}

gdb/dwarf2/read.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ dwarf2_per_bfd::locate_sections (asection *sectp,
13221322
bfd_size_type size = sectp->size;
13231323
warning (_("Discarding section %s which has an invalid size (%s) "
13241324
"[in module %s]"),
1325-
bfd_section_name (sectp), phex_nz (size, sizeof (size)),
1325+
bfd_section_name (sectp), phex_nz (size),
13261326
this->filename ());
13271327
}
13281328
else if (names.info.matches (sectp->name))

gdb/ravenscar-thread.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ ravenscar_thread_target::pid_to_str (ptid_t ptid)
503503
return beneath ()->pid_to_str (ptid);
504504

505505
return string_printf ("Ravenscar Thread 0x%s",
506-
phex_nz (ptid.tid (), sizeof (ULONGEST)));
506+
phex_nz (ptid.tid ()));
507507
}
508508

509509
CORE_ADDR

gdb/remote.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11650,7 +11650,7 @@ remote_target::remote_write_qxfer (const char *object_name,
1165011650
i = snprintf (rs->buf.data (), max_size,
1165111651
"qXfer:%s:write:%s:%s:",
1165211652
object_name, annex ? annex : "",
11653-
phex_nz (offset, sizeof offset));
11653+
phex_nz (offset));
1165411654
max_size -= (i + 1);
1165511655

1165611656
/* Escape as much data as fits into rs->buf. */
@@ -11715,8 +11715,8 @@ remote_target::remote_read_qxfer (const char *object_name,
1171511715
snprintf (rs->buf.data (), get_remote_packet_size () - 4,
1171611716
"qXfer:%s:read:%s:%s,%s",
1171711717
object_name, annex ? annex : "",
11718-
phex_nz (offset, sizeof offset),
11719-
phex_nz (n, sizeof n));
11718+
phex_nz (offset),
11719+
phex_nz (n));
1172011720
i = putpkt (rs->buf);
1172111721
if (i < 0)
1172211722
return TARGET_XFER_E_IO;
@@ -12014,7 +12014,7 @@ remote_target::search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
1201412014
i = snprintf (rs->buf.data (), max_size,
1201512015
"qSearch:memory:%s;%s;",
1201612016
phex_nz (start_addr, addr_size),
12017-
phex_nz (search_space_len, sizeof (search_space_len)));
12017+
phex_nz (search_space_len));
1201812018
max_size -= (i + 1);
1201912019

1202012020
/* Escape as much data as fits into rs->buf. */
@@ -13763,7 +13763,7 @@ remote_target::download_tracepoint (struct bp_location *loc)
1376313763
encode_actions_rsp (loc, &tdp_actions, &stepping_actions);
1376413764

1376513765
tpaddr = loc->address;
13766-
strcpy (addrbuf, phex (tpaddr, sizeof (CORE_ADDR)));
13766+
strcpy (addrbuf, phex (tpaddr));
1376713767
ret = snprintf (buf.data (), buf.size (), "QTDP:%x:%s:%c:%lx:%x",
1376813768
b->number, addrbuf, /* address */
1376913769
(b->enable_state == bp_enabled ? 'E' : 'D'),
@@ -14027,7 +14027,7 @@ remote_target::enable_tracepoint (struct bp_location *location)
1402714027

1402814028
xsnprintf (rs->buf.data (), get_remote_packet_size (), "QTEnable:%x:%s",
1402914029
location->owner->number,
14030-
phex (location->address, sizeof (CORE_ADDR)));
14030+
phex (location->address));
1403114031
putpkt (rs->buf);
1403214032
remote_get_noisy_reply ();
1403314033
if (rs->buf[0] == '\0')
@@ -14043,7 +14043,7 @@ remote_target::disable_tracepoint (struct bp_location *location)
1404314043

1404414044
xsnprintf (rs->buf.data (), get_remote_packet_size (), "QTDisable:%x:%s",
1404514045
location->owner->number,
14046-
phex (location->address, sizeof (CORE_ADDR)));
14046+
phex (location->address));
1404714047
putpkt (rs->buf);
1404814048
remote_get_noisy_reply ();
1404914049
if (rs->buf[0] == '\0')
@@ -15569,7 +15569,7 @@ remote_target::commit_requested_thread_options ()
1556915569

1557015570
*obuf_p++ = ';';
1557115571
obuf_p += xsnprintf (obuf_p, obuf_endp - obuf_p, "%s",
15572-
phex_nz (options, sizeof (options)));
15572+
phex_nz (options));
1557315573
if (tp->ptid != magic_null_ptid)
1557415574
{
1557515575
*obuf_p++ = ':';
@@ -15808,8 +15808,8 @@ create_fetch_memtags_request (gdb::char_vector &packet, CORE_ADDR address,
1580815808

1580915809
std::string request = string_printf ("qMemTags:%s,%s:%s",
1581015810
phex_nz (address, addr_size),
15811-
phex_nz (len, sizeof (len)),
15812-
phex_nz (type, sizeof (type)));
15811+
phex_nz (len),
15812+
phex_nz (type));
1581315813

1581415814
strcpy (packet.data (), request.c_str ());
1581515815
}
@@ -15843,8 +15843,8 @@ create_store_memtags_request (gdb::char_vector &packet, CORE_ADDR address,
1584315843
/* Put together the main packet, address and length. */
1584415844
std::string request = string_printf ("QMemTags:%s,%s:%s:",
1584515845
phex_nz (address, addr_size),
15846-
phex_nz (len, sizeof (len)),
15847-
phex_nz (type, sizeof (type)));
15846+
phex_nz (len),
15847+
phex_nz (type));
1584815848
request += bin2hex (tags.data (), tags.size ());
1584915849

1585015850
/* Check if we have exceeded the maximum packet size. */

gdb/solib-svr4.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,9 +2058,9 @@ solist_update_incremental (svr4_info *info, CORE_ADDR debug_base,
20582058

20592059
/* Unknown key=value pairs are ignored by the gdbstub. */
20602060
xsnprintf (annex, sizeof (annex), "lmid=%s;start=%s;prev=%s",
2061-
phex_nz (debug_base, sizeof (debug_base)),
2062-
phex_nz (lm, sizeof (lm)),
2063-
phex_nz (prev_lm, sizeof (prev_lm)));
2061+
phex_nz (debug_base),
2062+
phex_nz (lm),
2063+
phex_nz (prev_lm));
20642064
if (!svr4_current_sos_via_xfer_libraries (&library_list, annex))
20652065
return 0;
20662066

gdb/tracefile-tfile.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ tfile_write_status (struct trace_file_writer *self,
194194
if (ts->start_time)
195195
{
196196
fprintf (writer->fp, ";starttime:%s",
197-
phex_nz (ts->start_time, sizeof (ts->start_time)));
197+
phex_nz (ts->start_time));
198198
}
199199
if (ts->stop_time)
200200
{
201201
fprintf (writer->fp, ";stoptime:%s",
202-
phex_nz (ts->stop_time, sizeof (ts->stop_time)));
202+
phex_nz (ts->stop_time));
203203
}
204204
if (ts->notes != NULL)
205205
{
@@ -254,7 +254,7 @@ tfile_write_uploaded_tp (struct trace_file_writer *self,
254254
char buf[MAX_TRACE_UPLOAD];
255255

256256
fprintf (writer->fp, "tp T%x:%s:%c:%x:%x",
257-
utp->number, phex_nz (utp->addr, sizeof (utp->addr)),
257+
utp->number, phex_nz (utp->addr),
258258
(utp->enabled ? 'E' : 'D'), utp->step, utp->pass);
259259
if (utp->type == bp_fast_tracepoint)
260260
fprintf (writer->fp, ":F%x", utp->orig_size);
@@ -265,10 +265,10 @@ tfile_write_uploaded_tp (struct trace_file_writer *self,
265265
fprintf (writer->fp, "\n");
266266
for (const auto &act : utp->actions)
267267
fprintf (writer->fp, "tp A%x:%s:%s\n",
268-
utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act.get ());
268+
utp->number, phex_nz (utp->addr), act.get ());
269269
for (const auto &act : utp->step_actions)
270270
fprintf (writer->fp, "tp S%x:%s:%s\n",
271-
utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act.get ());
271+
utp->number, phex_nz (utp->addr), act.get ());
272272
if (utp->at_string)
273273
{
274274
encode_source_string (utp->number, utp->addr,
@@ -290,7 +290,7 @@ tfile_write_uploaded_tp (struct trace_file_writer *self,
290290
fprintf (writer->fp, "tp Z%s\n", buf);
291291
}
292292
fprintf (writer->fp, "tp V%x:%s:%x:%s\n",
293-
utp->number, phex_nz (utp->addr, sizeof (utp->addr)),
293+
utp->number, phex_nz (utp->addr),
294294
utp->hit_count,
295295
phex_nz (utp->traceframe_usage,
296296
sizeof (utp->traceframe_usage)));

gdb/tracepoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2818,7 +2818,7 @@ encode_source_string (int tpnum, ULONGEST addr,
28182818
if (80 + strlen (srctype) > buf_size)
28192819
error (_("Buffer too small for source encoding"));
28202820
sprintf (buf, "%x:%s:%s:%x:%x:",
2821-
tpnum, phex_nz (addr, sizeof (addr)),
2821+
tpnum, phex_nz (addr),
28222822
srctype, 0, (int) strlen (src));
28232823
if (strlen (buf) + strlen (src) * 2 >= buf_size)
28242824
error (_("Source string too long for buffer"));

0 commit comments

Comments
 (0)