mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-08-06 14:49:38 +08:00
Do not cast away const in agent_run_command
While investigating something else, I noticed some weird code in agent_run_command (use of memcpy rather than strcpy). Then I noticed that 'cmd' is used as both an in and out parameter, despite being const. Casting away const like this is bad. This patch removes the const and fixes the memcpy. I also added a static assert to assure myself that the code in gdbserver is correct -- gdbserver is passing its own buffer directly to agent_run_command. Reviewed-By: Andrew Burgess <aburgess@redhat.com>
This commit is contained in:
@ -4114,9 +4114,7 @@ linux_nat_target::static_tracepoint_markers_by_strid (const char *strid)
|
|||||||
/* Pause all */
|
/* Pause all */
|
||||||
target_stop (ptid);
|
target_stop (ptid);
|
||||||
|
|
||||||
memcpy (s, "qTfSTM", sizeof ("qTfSTM"));
|
strcpy (s, "qTfSTM");
|
||||||
s[sizeof ("qTfSTM")] = 0;
|
|
||||||
|
|
||||||
agent_run_command (pid, s, strlen (s) + 1);
|
agent_run_command (pid, s, strlen (s) + 1);
|
||||||
|
|
||||||
/* Unpause all. */
|
/* Unpause all. */
|
||||||
@ -4133,8 +4131,7 @@ linux_nat_target::static_tracepoint_markers_by_strid (const char *strid)
|
|||||||
}
|
}
|
||||||
while (*p++ == ','); /* comma-separated list */
|
while (*p++ == ','); /* comma-separated list */
|
||||||
|
|
||||||
memcpy (s, "qTsSTM", sizeof ("qTsSTM"));
|
strcpy (s, "qTsSTM");
|
||||||
s[sizeof ("qTsSTM")] = 0;
|
|
||||||
agent_run_command (pid, s, strlen (s) + 1);
|
agent_run_command (pid, s, strlen (s) + 1);
|
||||||
p = s;
|
p = s;
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,11 @@
|
|||||||
#include "gdbsupport/scoped_restore.h"
|
#include "gdbsupport/scoped_restore.h"
|
||||||
#include "gdbsupport/search.h"
|
#include "gdbsupport/search.h"
|
||||||
|
|
||||||
|
/* PBUFSIZ must also be at least as big as IPA_CMD_BUF_SIZE, because
|
||||||
|
the client state data is passed directly to some agent
|
||||||
|
functions. */
|
||||||
|
gdb_static_assert (PBUFSIZ >= IPA_CMD_BUF_SIZE);
|
||||||
|
|
||||||
#define require_running_or_return(BUF) \
|
#define require_running_or_return(BUF) \
|
||||||
if (!target_running ()) \
|
if (!target_running ()) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -6820,7 +6820,7 @@ run_inferior_command (char *cmd, int len)
|
|||||||
target_pause_all (false);
|
target_pause_all (false);
|
||||||
uninsert_all_breakpoints ();
|
uninsert_all_breakpoints ();
|
||||||
|
|
||||||
err = agent_run_command (pid, (const char *) cmd, len);
|
err = agent_run_command (pid, cmd, len);
|
||||||
|
|
||||||
reinsert_all_breakpoints ();
|
reinsert_all_breakpoints ();
|
||||||
target_unpause_all (false);
|
target_unpause_all (false);
|
||||||
|
@ -179,14 +179,16 @@ gdb_connect_sync_socket (int pid)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Execute an agent command in the inferior. PID is the value of pid of the
|
/* Execute an agent command in the inferior. PID is the value of pid
|
||||||
inferior. CMD is the buffer for command. GDB or GDBserver will store the
|
of the inferior. CMD is the buffer for command. It is assumed to
|
||||||
command into it and fetch the return result from CMD. The interaction
|
be at least IPA_CMD_BUF_SIZE bytes long. GDB or GDBserver will
|
||||||
between GDB/GDBserver and the agent is synchronized by a synchronization
|
store the command into it and fetch the return result from CMD.
|
||||||
socket. Return zero if success, otherwise return non-zero. */
|
The interaction between GDB/GDBserver and the agent is synchronized
|
||||||
|
by a synchronization socket. Return zero if success, otherwise
|
||||||
|
return non-zero. */
|
||||||
|
|
||||||
int
|
int
|
||||||
agent_run_command (int pid, const char *cmd, int len)
|
agent_run_command (int pid, char *cmd, int len)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int tid = agent_get_helper_thread_id ();
|
int tid = agent_get_helper_thread_id ();
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "gdbsupport/preprocessor.h"
|
#include "gdbsupport/preprocessor.h"
|
||||||
|
|
||||||
int agent_run_command (int pid, const char *cmd, int len);
|
int agent_run_command (int pid, char *cmd, int len);
|
||||||
|
|
||||||
int agent_look_up_symbols (void *);
|
int agent_look_up_symbols (void *);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user