Move savestring to common/common-utils.c, make gdbserver use it.
authorPedro Alves <palves@redhat.com>
Thu, 14 Feb 2013 17:11:41 +0000 (17:11 +0000)
committerPedro Alves <palves@redhat.com>
Thu, 14 Feb 2013 17:11:41 +0000 (17:11 +0000)
This makes gdbserver share gdb's savestring, instead of baking its own.

Tested on x86_64 Fedora 17.

gdb/
2013-02-14  Pedro Alves  <palves@redhat.com>

* utils.c (savestring): Don't #undef it.  Move function to
common/common-utils.c.
* common/common-utils.c: Include gdb_string.h.
(savestring): Move here from utils.c.
* common/common-utils.h (savestring): Declare.

gdb/gdbserver/
2013-02-14  Pedro Alves  <palves@redhat.com>

* tracepoint.c (save_string): Delete.
(add_tracepoint_action): Use savestring instead of save_string.

gdb/ChangeLog
gdb/common/common-utils.c
gdb/common/common-utils.h
gdb/gdbserver/ChangeLog
gdb/gdbserver/tracepoint.c
gdb/utils.c

index 3e91b36bc0120ae53bc0fbae3615f92d335ac903..318f7dff2b0dd71d2fe74b5b944a5c144a59e678 100644 (file)
@@ -1,3 +1,11 @@
+2013-02-14  Pedro Alves  <palves@redhat.com>
+
+       * utils.c (savestring): Don't #undef it.  Move function to
+       common/common-utils.c.
+       * common/common-utils.c: Include gdb_string.h.
+       (savestring): Move here from utils.c.
+       * common/common-utils.h (savestring): Declare.
+
 2013-02-14  Pedro Alves  <palves@redhat.com>
 
        * utils.c (savestring): Rename parameter 'size' to 'len'.
index 60093a47608482496122bf5d873da67624e324ef..4204abf8212016b2b854d1c5503decd2feb49632 100644 (file)
@@ -24,6 +24,7 @@
 #endif
 
 #include "gdb_assert.h"
+#include "gdb_string.h"
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -150,3 +151,13 @@ xsnprintf (char *str, size_t size, const char *format, ...)
 
   return ret;
 }
+
+char *
+savestring (const char *ptr, size_t len)
+{
+  char *p = (char *) xmalloc (len + 1);
+
+  memcpy (p, ptr, len);
+  p[len] = 0;
+  return p;
+}
index 2abc6d1ff427b30aaef1d190bff6b114228afd90..9b659d8dacedfcea05b0ed15d780e69ddbd01995 100644 (file)
@@ -47,4 +47,10 @@ char *xstrvprintf (const char *format, va_list ap)
 int xsnprintf (char *str, size_t size, const char *format, ...)
      ATTRIBUTE_PRINTF (3, 4);
 
+/* Make a copy of the string at PTR with LEN characters
+   (and add a null character at the end in the copy).
+   Uses malloc to get the space.  Returns the address of the copy.  */
+
+char *savestring (const char *ptr, size_t len);
+
 #endif
index 1a3ebfafcadb232867ba4364fe69afc41fcf8a98..e0669799cf8018fc35550acd0d705f39488f1961 100644 (file)
@@ -1,3 +1,8 @@
+2013-02-14  Pedro Alves  <palves@redhat.com>
+
+       * tracepoint.c (save_string): Delete.
+       (add_tracepoint_action): Use savestring instead of save_string.
+
 2013-02-12  Pedro Alves  <palves@redhat.com>
 
        * linux-xtensa-low.c: Ditto.
index 51b6a0c51d1e597bc2eef4838ea0b54b09f63d8a..0ffedaa134424ba15538640b6f663a82f615b590 100644 (file)
@@ -1896,18 +1896,6 @@ find_next_tracepoint_by_number (struct tracepoint *prev_tp, int num)
 
 #endif
 
-static char *
-save_string (const char *str, size_t len)
-{
-  char *s;
-
-  s = xmalloc (len + 1);
-  memcpy (s, str, len);
-  s[len] = '\0';
-
-  return s;
-}
-
 /* Append another action to perform when the tracepoint triggers.  */
 
 static void
@@ -2028,7 +2016,7 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet)
                         * tpoint->num_step_actions));
          tpoint->step_actions[tpoint->num_step_actions - 1] = action;
          tpoint->step_actions_str[tpoint->num_step_actions - 1]
-           = save_string (act_start, act - act_start);
+           = savestring (act_start, act - act_start);
        }
       else
        {
@@ -2041,7 +2029,7 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet)
                        sizeof (*tpoint->actions_str) * tpoint->numactions);
          tpoint->actions[tpoint->numactions - 1] = action;
          tpoint->actions_str[tpoint->numactions - 1]
-           = save_string (act_start, act - act_start);
+           = savestring (act_start, act - act_start);
        }
     }
 }
index 408c6ce0888a1e12605a6500e8140a5c612f3f7f..eb99f4b161ea086b4a1173064979d1b8180c03ca 100644 (file)
@@ -89,9 +89,6 @@ extern PTR realloc ();                /* ARI: PTR */
 extern void free ();
 #endif
 
-/* readline defines this.  */
-#undef savestring
-
 void (*deprecated_error_begin_hook) (void);
 
 /* Prototypes for local functions */
@@ -1186,20 +1183,6 @@ myread (int desc, char *addr, int len)
   return orglen;
 }
 
-/* Make a copy of the string at PTR with LEN characters
-   (and add a null character at the end in the copy).
-   Uses malloc to get the space.  Returns the address of the copy.  */
-
-char *
-savestring (const char *ptr, size_t len)
-{
-  char *p = (char *) xmalloc (len + 1);
-
-  memcpy (p, ptr, len);
-  p[len] = 0;
-  return p;
-}
-
 void
 print_spaces (int n, struct ui_file *file)
 {
This page took 0.036312 seconds and 4 git commands to generate.