Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Doug Evans <dje@google.com>
To: Pedro Alves <palves@redhat.com>, Yao Qi <yao@codesourcery.com>
Cc: gdb-patches <gdb-patches@sourceware.org>
Subject: [PATCH 2/3] gdbserver debug_printf+timestamps: delim_string_to_char_ptr_vec_append
Date: Thu, 16 Jan 2014 23:33:00 -0000	[thread overview]
Message-ID: <21208.27744.859752.267877@ruffy.mtv.corp.google.com> (raw)
In-Reply-To: <21208.27400.695984.88504@ruffy.mtv.corp.google.com>

Doug Evans writes:
 > v2 is now split into three parts:
 > 
 > 1/3 - move ASSERT_FUNCTION to FUNCTION_NAME in common-utils.h
 > 2/3 - create new function delim_string_to_char_ptr_vec_append in gdb_vecs.c
 > 3/3 - the actual debug_printf patch
 > 
 > I went with --debug[=timestamp] as the option naming.

2014-01-16  Doug Evans  <dje@google.com>

	* common/gdb_vecs.c (delim_string_to_char_ptr_vec_append): New
	function, contents of dirnames_to_char_ptr_vec_append moved here.
	(delim_string_to_char_ptr_vec): New function.
	(dirnames_to_char_ptr_vec_append): Rewrite.
	* common/gdb_vecs.h (delim_string_to_char_ptr_vec): Declare.

diff --git a/gdb/common/gdb_vecs.c b/gdb/common/gdb_vecs.c
index b256986..4a3330f 100644
--- a/gdb/common/gdb_vecs.c
+++ b/gdb/common/gdb_vecs.c
@@ -44,35 +44,60 @@ free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec)
   VEC_free (char_ptr, char_ptr_vec);
 }
 
-/* Extended version of dirnames_to_char_ptr_vec - additionally if *VECP is
-   non-NULL the new list elements from DIRNAMES are appended to the existing
-   *VECP list of entries.  *VECP address will be updated by this call.  */
+/* Worker function to split character delimiter separated string of fields
+   STR into a CHAR_PTR_VEC.  */
 
-void
-dirnames_to_char_ptr_vec_append (VEC (char_ptr) **vecp, const char *dirnames)
+static void
+delim_string_to_char_ptr_vec_append (VEC (char_ptr) **vecp,
+				     const char *str, char delimiter)
 {
   do
     {
       size_t this_len;
-      char *next_dir, *this_dir;
+      char *next_field, *this_field;
 
-      next_dir = strchr (dirnames, DIRNAME_SEPARATOR);
-      if (next_dir == NULL)
-	this_len = strlen (dirnames);
+      next_field = strchr (str, delimiter);
+      if (next_field == NULL)
+	this_len = strlen (str);
       else
 	{
-	  this_len = next_dir - dirnames;
-	  next_dir++;
+	  this_len = next_field - str;
+	  next_field++;
 	}
 
-      this_dir = xmalloc (this_len + 1);
-      memcpy (this_dir, dirnames, this_len);
-      this_dir[this_len] = '\0';
-      VEC_safe_push (char_ptr, *vecp, this_dir);
+      this_field = xmalloc (this_len + 1);
+      memcpy (this_field, str, this_len);
+      this_field[this_len] = '\0';
+      VEC_safe_push (char_ptr, *vecp, this_field);
 
-      dirnames = next_dir;
+      str = next_field;
     }
-  while (dirnames != NULL);
+  while (str != NULL);
+}
+
+/* Split STR, a list of DELIMITER-separated fields, into a CHAR_PTR_VEC.
+
+   You may modify the returned strings.
+   Read free_char_ptr_vec for its cleanup.  */
+
+VEC (char_ptr) *
+delim_string_to_char_ptr_vec (const char *str, char delimiter)
+{
+  VEC (char_ptr) *retval = NULL;
+  
+  delim_string_to_char_ptr_vec_append (&retval, str, delimiter);
+
+  return retval;
+}
+
+/* Extended version of dirnames_to_char_ptr_vec - additionally if *VECP is
+   non-NULL the new list elements from DIRNAMES are appended to the existing
+   *VECP list of entries.  *VECP address will be updated by this call.  */
+
+void
+dirnames_to_char_ptr_vec_append (VEC (char_ptr) **vecp, const char *dirnames)
+{
+  delim_string_to_char_ptr_vec_append (vecp, dirnames, DIRNAME_SEPARATOR);
 }
 
 /* Split DIRNAMES by DIRNAME_SEPARATOR delimiter and return a list of all the
diff --git a/gdb/common/gdb_vecs.h b/gdb/common/gdb_vecs.h
index 2978205..0606689 100644
--- a/gdb/common/gdb_vecs.h
+++ b/gdb/common/gdb_vecs.h
@@ -36,6 +36,9 @@ extern void free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec);
 extern struct cleanup *
   make_cleanup_free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec);
 
+extern VEC (char_ptr) *delim_string_to_char_ptr_vec (const char *str,
+						     char delimiter);
+
 extern void dirnames_to_char_ptr_vec_append (VEC (char_ptr) **vecp,
 					     const char *dirnames);
 


  parent reply	other threads:[~2014-01-16 23:33 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-17 21:47 [PATCH 4/6] gdbserver: Delimit debugging output for readability Doug Evans
2013-12-18 11:17 ` Pedro Alves
2014-01-15  0:47   ` Doug Evans
2014-01-16 17:22     ` Pedro Alves
2014-01-16 18:43       ` Doug Evans
2014-01-16 18:54         ` Pedro Alves
2014-01-16 23:28           ` [PATCH 0/3] Add debug_printf and timestamps to gdbserver Doug Evans
2014-01-16 23:31             ` [PATCH 1/3] gdbserver debug_printf+timestamps: FUNCTION_NAME Doug Evans
2014-01-17 12:46               ` Pedro Alves
2014-01-16 23:33             ` Doug Evans [this message]
2014-01-16 23:37             ` [PATCH 3/3, doc RFA] gdbserver debug_printf+timestamps: main patch Doug Evans
2014-01-17  2:58               ` Doug Evans
2014-01-17  7:04               ` Eli Zaretskii
2014-01-17 12:46               ` Pedro Alves
2014-01-17 22:45                 ` Doug Evans
2014-01-18  8:25                   ` Eli Zaretskii
2014-01-20 16:14                   ` Pedro Alves
2014-01-22 23:06                     ` Doug Evans
2014-01-16 18:39     ` [PATCH 4/6] gdbserver: Delimit debugging output for readability Yao Qi
2014-01-16 19:01       ` Doug Evans
2014-01-17  2:32         ` Joel Brobecker
2014-01-17  2:40         ` Joel Brobecker
2014-01-17 12:46         ` Pedro Alves
2014-01-17 12:59         ` Yao Qi
2014-01-20  5:42         ` Tom Tromey
2014-01-20 19:51           ` Doug Evans

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=21208.27744.859752.267877@ruffy.mtv.corp.google.com \
    --to=dje@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    --cc=yao@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox