From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14029 invoked by alias); 16 Jan 2014 23:33:58 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 14018 invoked by uid 89); 16 Jan 2014 23:33:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ob0-f201.google.com Received: from mail-ob0-f201.google.com (HELO mail-ob0-f201.google.com) (209.85.214.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 16 Jan 2014 23:33:55 +0000 Received: by mail-ob0-f201.google.com with SMTP id gq1so283929obb.2 for ; Thu, 16 Jan 2014 15:33:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:mime-version:content-type :content-transfer-encoding:to:cc:subject:in-reply-to:references; bh=l4LYyFd3WW1QRbvdIfCU+5Gj2Oa+W6TGsRmKi0HG+SQ=; b=Z9s0yAU1sLcE/D5SOTCSbWtJvaV91vsc58qwaMNcsojEesOa6fWOBRHINt97/4VrU0 JdUya7KRIqU/xAzq56c2Hb+CGGQiHN6bcXu7DE7YTVMyIXy3756EvxFQvK44WwGYcsTA QBP94y49AAB8Q/QSKpgg+89Cmkiq3VSfQsfw6TxmJaTJsgYbqXdhDbMQoLt2dMLLnVBF qSLLwF7RZCbbSgcpOfXbJBHya1KmM01y9aGXMw9dW2x8ZjmHjrHegSF2rwN+uKRzJXVy pha1wpefVxuqo35tRKAtbOjhzCv4W1KlHCWCLGgd7j6Bqn5bCbGF+jdTicNG+gUlvVDj yp/Q== X-Gm-Message-State: ALoCoQkGtarVJmaRHreI9yXr61G3LNReQDnEVnVFQDSjMMqgLymLEy7obFwS81ni//eVC6R+Jodmd21i68NvGaoYIvf6d7tZMutwxmbXAHd+YrPekxNvMUTI5b9O0SuubbB9hlcAvSN38kJ015ufaFaSdt6w09h72QeELI+KlKJ2BKEqtcpxbAnRi4LAcNnASMzRf5vSIrfz4k/dRQQ2RjGgkuGGCB0Rvw== X-Received: by 10.182.112.231 with SMTP id it7mr4383719obb.22.1389915234101; Thu, 16 Jan 2014 15:33:54 -0800 (PST) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id v64si2973123yhm.3.2014.01.16.15.33.54 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Jan 2014 15:33:54 -0800 (PST) Received: from ruffy.mtv.corp.google.com (ruffy.mtv.corp.google.com [172.17.128.44]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 65B3231C071; Thu, 16 Jan 2014 15:33:53 -0800 (PST) From: Doug Evans Message-ID: <21208.27744.859752.267877@ruffy.mtv.corp.google.com> Date: Thu, 16 Jan 2014 23:33:00 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: Pedro Alves , Yao Qi cc: gdb-patches Subject: [PATCH 2/3] gdbserver debug_printf+timestamps: delim_string_to_char_ptr_vec_append In-Reply-To: <21208.27400.695984.88504@ruffy.mtv.corp.google.com> References: <52B1842F.5020401@redhat.com> <21205.55987.69477.892571@ruffy.mtv.corp.google.com> <52D81569.3080006@redhat.com> <52D82AD5.7000306@redhat.com> <21208.27400.695984.88504@ruffy.mtv.corp.google.com> X-IsSubscribed: yes X-SW-Source: 2014-01/txt/msg00659.txt.bz2 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 * 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);