Constify unpack_varlen_hex & fix fallout

I ran into non-const unpack_varlen_hex while working on something
else, and decided to just fix it first.  Ends up constifying a good
deal of remote packet parsing.

gdb/ChangeLog:
2017-09-29  Pedro Alves  <palves@redhat.com>

	* common/rsp-low.c (unpack_varlen_hex): Constify.
	* common/rsp-low.h (unpack_varlen_hex): Constify.
	* linux-nat.c (linux_child_static_tracepoint_markers_by_strid):
	Constify.
	* remote.c (remote_set_permissions, read_ptid)
	(remote_current_thread, remote_get_threads_with_qthreadinfo)
	(remote_static_tracepoint_marker_at)
	(remote_static_tracepoint_markers_by_strid)
	(stop_reply_extract_thread, remote_parse_stop_reply): Constify.
	* tracepoint.c (parse_trace_status, parse_tracepoint_status)
	(parse_tracepoint_definition, parse_tsv_definition)
	(parse_static_tracepoint_marker_definition): Constify.
	* tracepoint.h (parse_static_tracepoint_marker_definition)
	(parse_trace_status, parse_tracepoint_status)
	(parse_tracepoint_definition, parse_tsv_definition): Constify.

gdb/gdbserver/ChangeLog:
2017-09-29  Pedro Alves  <palves@redhat.com>

	* ax.c (gdb_parse_agent_expr): Constify.
	* ax.h (gdb_parse_agent_expr): Constify.
	* mem-break.c (add_breakpoint_condition, add_breakpoint_commands):
	Constify.
	* mem-break.h (add_breakpoint_condition, add_breakpoint_commands): Constify.
	* remote-utils.c (hex_or_minus_one, read_ptid): Constify.
	* remote-utils.h (read_ptid): Constify.
	* server.c (handle_qxfer_exec_file, handle_query, handle_v_cont)
	(process_point_options, process_serial_event): Constify.
	* tracepoint.c (add_tracepoint_action, cmd_qtdp, cmd_qtdpsrc)
	(cmd_qtdv, cmd_qtenable_disable, cmd_qtro, cmd_qtframe, cmd_qtp)
	(cmd_qtbuffer): Constify.
This commit is contained in:
Pedro Alves 2017-09-29 17:15:36 +01:00
parent b6bb34680b
commit 256642e857
16 changed files with 115 additions and 82 deletions

View File

@ -1,3 +1,21 @@
2017-09-29 Pedro Alves <palves@redhat.com>
* common/rsp-low.c (unpack_varlen_hex): Constify.
* common/rsp-low.h (unpack_varlen_hex): Constify.
* linux-nat.c (linux_child_static_tracepoint_markers_by_strid):
Constify.
* remote.c (remote_set_permissions, read_ptid)
(remote_current_thread, remote_get_threads_with_qthreadinfo)
(remote_static_tracepoint_marker_at)
(remote_static_tracepoint_markers_by_strid)
(stop_reply_extract_thread, remote_parse_stop_reply): Constify.
* tracepoint.c (parse_trace_status, parse_tracepoint_status)
(parse_tracepoint_definition, parse_tsv_definition)
(parse_static_tracepoint_marker_definition): Constify.
* tracepoint.h (parse_static_tracepoint_marker_definition)
(parse_trace_status, parse_tracepoint_status)
(parse_tracepoint_definition, parse_tsv_definition): Constify.
2017-09-29 Pedro Alves <palves@redhat.com>
* remote.c (target_buf, target_buf_size): Delete.

View File

@ -92,8 +92,8 @@ pack_hex_byte (char *pkt, int byte)
/* See rsp-low.h. */
char *
unpack_varlen_hex (char *buff, /* packet to parse */
const char *
unpack_varlen_hex (const char *buff, /* packet to parse */
ULONGEST *result)
{
int nibble;

View File

@ -41,7 +41,7 @@ extern char *pack_hex_byte (char *pkt, int byte);
in RESULT. Reads until a non-hex digit is seen. Returns a pointer
to the terminating character. */
extern char *unpack_varlen_hex (char *buff, ULONGEST *result);
extern const char *unpack_varlen_hex (const char *buff, ULONGEST *result);
/* HEX is a string of characters representing hexadecimal digits.
Convert pairs of hex digits to bytes and store sequentially into

View File

@ -1,3 +1,18 @@
2017-09-29 Pedro Alves <palves@redhat.com>
* ax.c (gdb_parse_agent_expr): Constify.
* ax.h (gdb_parse_agent_expr): Constify.
* mem-break.c (add_breakpoint_condition, add_breakpoint_commands):
Constify.
* mem-break.h (add_breakpoint_condition, add_breakpoint_commands): Constify.
* remote-utils.c (hex_or_minus_one, read_ptid): Constify.
* remote-utils.h (read_ptid): Constify.
* server.c (handle_qxfer_exec_file, handle_query, handle_v_cont)
(process_point_options, process_serial_event): Constify.
* tracepoint.c (add_tracepoint_action, cmd_qtdp, cmd_qtdpsrc)
(cmd_qtdv, cmd_qtenable_disable, cmd_qtro, cmd_qtframe, cmd_qtp)
(cmd_qtbuffer): Constify.
2017-09-29 Pedro Alves <palves@redhat.com>
* proc-service.c (ps_pdread): Return PS_ERR if reading memory

View File

@ -95,9 +95,9 @@ gdb_agent_op_name (int op)
of bytes in expression, a comma, and then the bytes. */
struct agent_expr *
gdb_parse_agent_expr (char **actparm)
gdb_parse_agent_expr (const char **actparm)
{
char *act = *actparm;
const char *act = *actparm;
ULONGEST xlen;
struct agent_expr *aexpr;

View File

@ -55,7 +55,7 @@ struct agent_expr
/* The packet form of an agent expression consists of an 'X', number
of bytes in expression, a comma, and then the bytes. */
struct agent_expr *gdb_parse_agent_expr (char **actparm);
struct agent_expr *gdb_parse_agent_expr (const char **actparm);
/* Release an agent expression. */
void gdb_free_agent_expr (struct agent_expr *aexpr);

View File

@ -1269,9 +1269,9 @@ add_condition_to_breakpoint (struct gdb_breakpoint *bp,
/* Add a target-side condition CONDITION to a breakpoint. */
int
add_breakpoint_condition (struct gdb_breakpoint *bp, char **condition)
add_breakpoint_condition (struct gdb_breakpoint *bp, const char **condition)
{
char *actparm = *condition;
const char *actparm = *condition;
struct agent_expr *cond;
if (condition == NULL)
@ -1367,10 +1367,10 @@ add_commands_to_breakpoint (struct gdb_breakpoint *bp,
/* Add a target-side command COMMAND to the breakpoint at ADDR. */
int
add_breakpoint_commands (struct gdb_breakpoint *bp, char **command,
add_breakpoint_commands (struct gdb_breakpoint *bp, const char **command,
int persist)
{
char *actparm = *command;
const char *actparm = *command;
struct agent_expr *cmd;
if (command == NULL)

View File

@ -114,14 +114,15 @@ void clear_breakpoint_conditions_and_commands (struct gdb_breakpoint *bp);
Returns false on failure. On success, advances CONDITION pointer
past the condition and returns true. */
int add_breakpoint_condition (struct gdb_breakpoint *bp, char **condition);
int add_breakpoint_condition (struct gdb_breakpoint *bp,
const char **condition);
/* Set target-side commands COMMANDS to the breakpoint at ADDR.
Returns false on failure. On success, advances COMMANDS past the
commands and returns true. If PERSIST, the commands should run
even while GDB is disconnected. */
int add_breakpoint_commands (struct gdb_breakpoint *bp, char **commands,
int add_breakpoint_commands (struct gdb_breakpoint *bp, const char **commands,
int persist);
int any_persistent_commands (void);

View File

@ -533,7 +533,7 @@ write_ptid (char *buf, ptid_t ptid)
}
static ULONGEST
hex_or_minus_one (char *buf, char **obuf)
hex_or_minus_one (const char *buf, const char **obuf)
{
ULONGEST ret;
@ -554,10 +554,10 @@ hex_or_minus_one (char *buf, char **obuf)
/* Extract a PTID from BUF. If non-null, OBUF is set to the to one
passed the last parsed char. Returns null_ptid on error. */
ptid_t
read_ptid (char *buf, char **obuf)
read_ptid (const char *buf, const char **obuf)
{
char *p = buf;
char *pp;
const char *p = buf;
const char *pp;
ULONGEST pid = 0, tid = 0;
if (*p == 'p')

View File

@ -28,7 +28,7 @@ int gdb_connected (void);
#define STDIO_CONNECTION_NAME "stdio"
int remote_connection_is_stdio (void);
ptid_t read_ptid (char *buf, char **obuf);
ptid_t read_ptid (const char *buf, const char **obuf);
char *write_ptid (char *buf, ptid_t ptid);
int putpkt (char *buf);

View File

@ -1427,7 +1427,7 @@ handle_qxfer_auxv (const char *annex,
/* Handle qXfer:exec-file:read. */
static int
handle_qxfer_exec_file (const char *const_annex,
handle_qxfer_exec_file (const char *annex,
gdb_byte *readbuf, const gdb_byte *writebuf,
ULONGEST offset, LONGEST len)
{
@ -1438,7 +1438,7 @@ handle_qxfer_exec_file (const char *const_annex,
if (the_target->pid_to_exec_file == NULL || writebuf != NULL)
return -2;
if (const_annex[0] == '\0')
if (annex[0] == '\0')
{
if (current_thread == NULL)
return -1;
@ -1447,11 +1447,7 @@ handle_qxfer_exec_file (const char *const_annex,
}
else
{
char *annex = (char *) alloca (strlen (const_annex) + 1);
strcpy (annex, const_annex);
annex = unpack_varlen_hex (annex, &pid);
if (annex[0] != '\0')
return -1;
}
@ -2535,7 +2531,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
if (the_target->get_tib_address != NULL
&& startswith (own_buf, "qGetTIBAddr:"))
{
char *annex;
const char *annex;
int n;
CORE_ADDR tlb;
ptid_t ptid = read_ptid (own_buf + 12, &annex);
@ -2623,7 +2619,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
if (startswith (own_buf, "qCRC:"))
{
/* CRC check (compare-section). */
char *comma;
const char *comma;
ULONGEST base;
int len;
unsigned long long crc;
@ -2732,7 +2728,7 @@ handle_pending_status (const struct thread_resume *resumption,
static void
handle_v_cont (char *own_buf)
{
char *p, *q;
const char *p;
int n = 0, i = 0;
struct thread_resume *resume_info;
struct thread_resume default_action { null_ptid };
@ -2771,8 +2767,8 @@ handle_v_cont (char *own_buf)
if (p[0] == 'S' || p[0] == 'C')
{
int sig;
sig = strtol (p + 1, &q, 16);
char *q;
int sig = strtol (p + 1, &q, 16);
if (p == q)
goto err;
p = q;
@ -2809,6 +2805,7 @@ handle_v_cont (char *own_buf)
}
else if (p[0] == ':')
{
const char *q;
ptid_t ptid = read_ptid (p + 1, &q);
if (p == q)
@ -4009,9 +4006,9 @@ main (int argc, char *argv[])
after the last processed option. */
static void
process_point_options (struct gdb_breakpoint *bp, char **packet)
process_point_options (struct gdb_breakpoint *bp, const char **packet)
{
char *dataptr = *packet;
const char *dataptr = *packet;
int persist;
/* Check if data has the correct format. */
@ -4273,7 +4270,7 @@ process_serial_event (void)
char type = own_buf[1];
int res;
const int insert = ch == 'Z';
char *p = &own_buf[3];
const char *p = &own_buf[3];
p = unpack_varlen_hex (p, &addr);
kind = strtol (p + 1, &dataptr, 16);
@ -4293,7 +4290,8 @@ process_serial_event (void)
is telling us to drop that list and use this one
instead. */
clear_breakpoint_conditions_and_commands (bp);
process_point_options (bp, &dataptr);
const char *options = dataptr;
process_point_options (bp, &options);
}
}
else

View File

@ -1910,9 +1910,9 @@ find_next_tracepoint_by_number (struct tracepoint *prev_tp, int num)
/* Append another action to perform when the tracepoint triggers. */
static void
add_tracepoint_action (struct tracepoint *tpoint, char *packet)
add_tracepoint_action (struct tracepoint *tpoint, const char *packet)
{
char *act;
const char *act;
if (*packet == 'S')
{
@ -1924,7 +1924,7 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet)
while (*act)
{
char *act_start = act;
const char *act_start = act;
struct tracepoint_action *action = NULL;
switch (*act)
@ -2485,8 +2485,7 @@ cmd_qtdp (char *own_buf)
ULONGEST addr;
ULONGEST count;
struct tracepoint *tpoint;
char *actparm;
char *packet = own_buf;
const char *packet = own_buf;
packet += strlen ("QTDP:");
@ -2546,9 +2545,7 @@ cmd_qtdp (char *own_buf)
}
else if (*packet == 'X')
{
actparm = (char *) packet;
tpoint->cond = gdb_parse_agent_expr (&actparm);
packet = actparm;
tpoint->cond = gdb_parse_agent_expr (&packet);
}
else if (*packet == '-')
break;
@ -2657,8 +2654,9 @@ cmd_qtdpsrc (char *own_buf)
{
ULONGEST num, addr, start, slen;
struct tracepoint *tpoint;
char *packet = own_buf;
char *saved, *srctype, *src;
const char *packet = own_buf;
const char *saved;
char *srctype, *src;
size_t nbytes;
struct source_string *last, *newlast;
@ -2720,7 +2718,7 @@ cmd_qtdv (char *own_buf)
char *varname;
size_t nbytes;
struct trace_state_variable *tsv;
char *packet = own_buf;
const char *packet = own_buf;
packet += strlen ("QTDV:");
@ -2748,7 +2746,7 @@ cmd_qtdv (char *own_buf)
static void
cmd_qtenable_disable (char *own_buf, int enable)
{
char *packet = own_buf;
const char *packet = own_buf;
ULONGEST num, addr;
struct tracepoint *tp;
@ -2870,7 +2868,7 @@ cmd_qtro (char *own_buf)
{
ULONGEST start, end;
struct readonly_region *roreg;
char *packet = own_buf;
const char *packet = own_buf;
trace_debug ("Want to mark readonly regions");
@ -3557,7 +3555,7 @@ cmd_qtframe (char *own_buf)
ULONGEST frame, pc, lo, hi, num;
int tfnum, tpnum;
struct traceframe *tframe;
char *packet = own_buf;
const char *packet = own_buf;
packet += strlen ("QTFrame:");
@ -3712,7 +3710,7 @@ cmd_qtp (char *own_buf)
{
ULONGEST num, addr;
struct tracepoint *tpoint;
char *packet = own_buf;
const char *packet = own_buf;
packet += strlen ("qTP:");
@ -4005,7 +4003,7 @@ cmd_qtbuffer (char *own_buf)
{
ULONGEST offset, num, tot;
unsigned char *tbp;
char *packet = own_buf;
const char *packet = own_buf;
packet += strlen ("qTBuffer:");

View File

@ -4291,7 +4291,7 @@ linux_child_static_tracepoint_markers_by_strid (struct target_ops *self,
int pid = ptid_get_pid (inferior_ptid);
VEC(static_tracepoint_marker_p) *markers = NULL;
struct static_tracepoint_marker *marker = NULL;
char *p = s;
const char *p = s;
ptid_t ptid = ptid_build (pid, 0, 0);
/* Pause all */

View File

@ -185,7 +185,7 @@ static void show_remote_protocol_packet_cmd (struct ui_file *file,
const char *value);
static char *write_ptid (char *buf, const char *endbuf, ptid_t ptid);
static ptid_t read_ptid (char *buf, char **obuf);
static ptid_t read_ptid (const char *buf, const char **obuf);
static void remote_set_permissions (struct target_ops *self);
@ -592,7 +592,7 @@ remote_get_noisy_reply ()
{
ULONGEST ul;
CORE_ADDR from, to, org_to;
char *p, *pp;
const char *p, *pp;
int adjusted_size = 0;
int relocated = 0;
@ -2445,14 +2445,15 @@ write_ptid (char *buf, const char *endbuf, ptid_t ptid)
return buf;
}
/* Extract a PTID from BUF. If non-null, OBUF is set to the to one
passed the last parsed char. Returns null_ptid on error. */
/* Extract a PTID from BUF. If non-null, OBUF is set to one past the
last parsed char. Returns null_ptid if no thread id is found, and
throws an error if the thread id has an invalid format. */
static ptid_t
read_ptid (char *buf, char **obuf)
read_ptid (const char *buf, const char **obuf)
{
char *p = buf;
char *pp;
const char *p = buf;
const char *pp;
ULONGEST pid = 0, tid = 0;
if (*p == 'p')
@ -3088,7 +3089,7 @@ remote_current_thread (ptid_t oldpid)
getpkt (&rs->buf, &rs->buf_size, 0);
if (rs->buf[0] == 'Q' && rs->buf[1] == 'C')
{
char *obuf;
const char *obuf;
ptid_t result;
result = read_ptid (&rs->buf[2], &obuf);
@ -3232,7 +3233,7 @@ remote_get_threads_with_qthreadinfo (struct target_ops *ops,
if (rs->use_threadinfo_query)
{
char *bufp;
const char *bufp;
putpkt ("qfThreadInfo");
getpkt (&rs->buf, &rs->buf_size, 0);
@ -3482,7 +3483,7 @@ remote_static_tracepoint_marker_at (struct target_ops *self, CORE_ADDR addr,
if (*p++ == 'm')
{
parse_static_tracepoint_marker_definition (p, &p, marker);
parse_static_tracepoint_marker_definition (p, NULL, marker);
return 1;
}
@ -3497,7 +3498,7 @@ remote_static_tracepoint_markers_by_strid (struct target_ops *self,
VEC(static_tracepoint_marker_p) *markers = NULL;
struct static_tracepoint_marker *marker = NULL;
struct cleanup *old_chain;
char *p;
const char *p;
/* Ask for a first packet of static tracepoint marker
definition. */
@ -3790,7 +3791,7 @@ stop_reply_extract_thread (char *stop_reply)
{
if (stop_reply[0] == 'T' && strlen (stop_reply) > 3)
{
char *p;
const char *p;
/* Txx r:val ; r:val (...) */
p = &stop_reply[3];
@ -3798,7 +3799,7 @@ stop_reply_extract_thread (char *stop_reply)
/* Look for "register" named "thread". */
while (*p != '\0')
{
char *p1;
const char *p1;
p1 = strchr (p, ':');
if (p1 == NULL)
@ -6836,7 +6837,7 @@ remote_parse_stop_reply (char *buf, struct stop_reply *event)
{
struct remote_arch_state *rsa = get_remote_arch_state ();
ULONGEST addr;
char *p;
const char *p;
int skipregs = 0;
event->ptid = null_ptid;
@ -6860,7 +6861,7 @@ remote_parse_stop_reply (char *buf, struct stop_reply *event)
p = &buf[3]; /* after Txx */
while (*p)
{
char *p1;
const char *p1;
int fieldsize;
p1 = strchr (p, ':');
@ -6998,7 +6999,7 @@ Packet: '%s'\n"),
else
{
ULONGEST pnum;
char *p_temp;
const char *p_temp;
if (skipregs)
{
@ -7068,7 +7069,7 @@ Packet: '%s'\n"),
break;
case 'w': /* Thread exited. */
{
char *p;
const char *p;
ULONGEST value;
event->ws.kind = TARGET_WAITKIND_THREAD_EXITED;
@ -7082,7 +7083,7 @@ Packet: '%s'\n"),
case 'W': /* Target exited. */
case 'X':
{
char *p;
const char *p;
int pid;
ULONGEST value;

View File

@ -3405,9 +3405,9 @@ merge_uploaded_trace_state_variables (struct uploaded_tsv **uploaded_tsvs)
the remote protocol and the trace file reader. */
void
parse_trace_status (char *line, struct trace_status *ts)
parse_trace_status (const char *line, struct trace_status *ts)
{
char *p = line, *p1, *p2, *p3, *p_temp;
const char *p = line, *p1, *p2, *p3, *p_temp;
int end;
ULONGEST val;
@ -3565,7 +3565,7 @@ Status line: '%s'\n"), p, line);
}
void
parse_tracepoint_status (char *p, struct breakpoint *bp,
parse_tracepoint_status (const char *p, struct breakpoint *bp,
struct uploaded_tp *utp)
{
ULONGEST uval;
@ -3588,14 +3588,15 @@ parse_tracepoint_status (char *p, struct breakpoint *bp,
an "uploaded tracepoint". */
void
parse_tracepoint_definition (char *line, struct uploaded_tp **utpp)
parse_tracepoint_definition (const char *line, struct uploaded_tp **utpp)
{
char *p;
const char *p;
char piece;
ULONGEST num, addr, step, pass, orig_size, xlen, start;
int enabled, end;
enum bptype type;
char *cond, *srctype, *buf;
const char *srctype;
char *cond, *buf;
struct uploaded_tp *utp = NULL;
p = line;
@ -3703,9 +3704,10 @@ parse_tracepoint_definition (char *line, struct uploaded_tp **utpp)
uploaded object. */
void
parse_tsv_definition (char *line, struct uploaded_tsv **utsvp)
parse_tsv_definition (const char *line, struct uploaded_tsv **utsvp)
{
char *p, *buf;
const char *p;
char *buf;
ULONGEST num, initval, builtin;
int end;
struct uploaded_tsv *utsv = NULL;
@ -3749,10 +3751,10 @@ free_current_marker (void *arg)
the parsed marker definition. */
void
parse_static_tracepoint_marker_definition (char *line, char **pp,
parse_static_tracepoint_marker_definition (const char *line, const char **pp,
struct static_tracepoint_marker *marker)
{
char *p, *endp;
const char *p, *endp;
ULONGEST addr;
int end;

View File

@ -295,7 +295,7 @@ private:
};
extern void parse_static_tracepoint_marker_definition
(char *line, char **pp,
(const char *line, const char **pp,
struct static_tracepoint_marker *marker);
extern void release_static_tracepoint_marker (struct static_tracepoint_marker *);
extern void free_current_marker (void *arg);
@ -342,14 +342,14 @@ extern int encode_source_string (int num, ULONGEST addr,
const char *srctype, const char *src,
char *buf, int buf_size);
extern void parse_trace_status (char *line, struct trace_status *ts);
extern void parse_trace_status (const char *line, struct trace_status *ts);
extern void parse_tracepoint_status (char *p, struct breakpoint *tp,
extern void parse_tracepoint_status (const char *p, struct breakpoint *tp,
struct uploaded_tp *utp);
extern void parse_tracepoint_definition (char *line,
extern void parse_tracepoint_definition (const char *line,
struct uploaded_tp **utpp);
extern void parse_tsv_definition (char *line, struct uploaded_tsv **utsvp);
extern void parse_tsv_definition (const char *line, struct uploaded_tsv **utsvp);
extern struct uploaded_tp *get_uploaded_tp (int num, ULONGEST addr,
struct uploaded_tp **utpp);