aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-02-14 07:03:11 -0700
committerTom Tromey <tromey@adacore.com>2023-02-14 09:01:18 -0700
commit81aa19c303c94f549cb9ae343cfe4b635b4e888c (patch)
tree804ffe2eec706e0e18732b5724ebcf5d737f9e7a /gdbsupport
parent5bed9dc992a0136d403a7addb29a2ed822fd4fd2 (diff)
downloadgdb-81aa19c303c94f549cb9ae343cfe4b635b4e888c.zip
gdb-81aa19c303c94f549cb9ae343cfe4b635b4e888c.tar.gz
gdb-81aa19c303c94f549cb9ae343cfe4b635b4e888c.tar.bz2
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>
Diffstat (limited to 'gdbsupport')
-rw-r--r--gdbsupport/agent.cc14
-rw-r--r--gdbsupport/agent.h2
2 files changed, 9 insertions, 7 deletions
diff --git a/gdbsupport/agent.cc b/gdbsupport/agent.cc
index 531807b..81c925d 100644
--- a/gdbsupport/agent.cc
+++ b/gdbsupport/agent.cc
@@ -179,14 +179,16 @@ gdb_connect_sync_socket (int pid)
#endif
}
-/* Execute an agent command in the inferior. PID is the value of pid of the
- inferior. CMD is the buffer for command. GDB or GDBserver will store the
- command into it and fetch the return result from CMD. The interaction
- between GDB/GDBserver and the agent is synchronized by a synchronization
- socket. Return zero if success, otherwise return non-zero. */
+/* Execute an agent command in the inferior. PID is the value of pid
+ of the inferior. CMD is the buffer for command. It is assumed to
+ be at least IPA_CMD_BUF_SIZE bytes long. GDB or GDBserver will
+ store the command into it and fetch the return result from CMD.
+ The interaction between GDB/GDBserver and the agent is synchronized
+ by a synchronization socket. Return zero if success, otherwise
+ return non-zero. */
int
-agent_run_command (int pid, const char *cmd, int len)
+agent_run_command (int pid, char *cmd, int len)
{
int fd;
int tid = agent_get_helper_thread_id ();
diff --git a/gdbsupport/agent.h b/gdbsupport/agent.h
index dceb33f..7a258e2 100644
--- a/gdbsupport/agent.h
+++ b/gdbsupport/agent.h
@@ -22,7 +22,7 @@
#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 *);