From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13310 invoked by alias); 14 Feb 2013 17:14:22 -0000 Received: (qmail 13300 invoked by uid 22791); 14 Feb 2013 17:14:19 -0000 X-SWARE-Spam-Status: No, hits=-7.6 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,KHOP_THREADED,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_CP,TW_XS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 14 Feb 2013 17:14:13 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1EHEDGl019644 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 14 Feb 2013 12:14:13 -0500 Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1EHEBBn011347 for ; Thu, 14 Feb 2013 12:14:12 -0500 Subject: [COMMIT PATCH 2/2] Move savestring to common/common-utils.c, make gdbserver use it. To: gdb-patches@sourceware.org From: Pedro Alves Date: Thu, 14 Feb 2013 17:14:00 -0000 Message-ID: <20130214171411.2223.32326.stgit@brno.lan> In-Reply-To: <20130214171404.2223.83713.stgit@brno.lan> References: <20130214171404.2223.83713.stgit@brno.lan> User-Agent: StGit/0.16 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 X-SW-Source: 2013-02/txt/msg00360.txt.bz2 This makes gdbserver share gdb's savestring, instead of baking its own. Tested on x86_64 Fedora 17. gdb/ 2013-02-14 Pedro Alves * 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 * tracepoint.c (save_string): Delete. (add_tracepoint_action): Use savestring instead of save_string. --- gdb/common/common-utils.c | 11 +++++++++++ gdb/common/common-utils.h | 6 ++++++ gdb/gdbserver/tracepoint.c | 16 ++-------------- gdb/utils.c | 17 ----------------- 4 files changed, 19 insertions(+), 31 deletions(-) diff --git a/gdb/common/common-utils.c b/gdb/common/common-utils.c index 60093a4..4204abf 100644 --- a/gdb/common/common-utils.c +++ b/gdb/common/common-utils.c @@ -24,6 +24,7 @@ #endif #include "gdb_assert.h" +#include "gdb_string.h" #include #include @@ -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; +} diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h index 2abc6d1..9b659d8 100644 --- a/gdb/common/common-utils.h +++ b/gdb/common/common-utils.h @@ -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 diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c index 51b6a0c..0ffedaa 100644 --- a/gdb/gdbserver/tracepoint.c +++ b/gdb/gdbserver/tracepoint.c @@ -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); } } } diff --git a/gdb/utils.c b/gdb/utils.c index 408c6ce..eb99f4b 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -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) {