From patchwork Sun Jan 3 09:19:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 10202 Received: (qmail 65978 invoked by alias); 3 Jan 2016 09:19:28 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 65961 invoked by uid 89); 3 Jan 2016 09:19:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=1718, *regs, regs, 5296 X-HELO: smtp.gentoo.org Received: from smtp.gentoo.org (HELO smtp.gentoo.org) (140.211.166.183) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sun, 03 Jan 2016 09:19:24 +0000 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id B1E6D340139 for ; Sun, 3 Jan 2016 09:19:22 +0000 (UTC) From: Mike Frysinger To: gdb-patches@sourceware.org Subject: [PATCH] sim: use libiberty countargv in more places [committed] Date: Sun, 3 Jan 2016 04:19:21 -0500 Message-Id: <1451812761-11101-1-git-send-email-vapier@gentoo.org> X-IsSubscribed: yes A bunch of places open code the countargv implementation, or outright duplicate it (as count_argc). Replace all of those w/countargv. --- sim/arm/ChangeLog | 5 +++++ sim/arm/wrapper.c | 7 +------ sim/bfin/ChangeLog | 6 ++++++ sim/bfin/interp.c | 24 +++++------------------- sim/common/ChangeLog | 5 +++++ sim/common/sim-options.c | 3 +-- sim/erc32/ChangeLog | 4 ++++ sim/erc32/interf.c | 3 +-- sim/sh/ChangeLog | 5 +++++ sim/sh/interp.c | 20 +++----------------- sim/sh64/ChangeLog | 5 +++++ sim/sh64/sh64.c | 22 +++------------------- 12 files changed, 44 insertions(+), 65 deletions(-) diff --git a/sim/arm/ChangeLog b/sim/arm/ChangeLog index a0b00f2..e9346c1 100644 --- a/sim/arm/ChangeLog +++ b/sim/arm/ChangeLog @@ -1,5 +1,10 @@ 2016-01-03 Mike Frysinger + * wrapper.c (sim_target_parse_arg_array): Replace for loop with + a call to countargv. + +2016-01-03 Mike Frysinger + * configure.ac (SIM_AC_OPTION_HOSTENDIAN): Delete. * configure: Regenerate. diff --git a/sim/arm/wrapper.c b/sim/arm/wrapper.c index 3938f3c..274b294 100644 --- a/sim/arm/wrapper.c +++ b/sim/arm/wrapper.c @@ -772,12 +772,7 @@ sim_target_parse_command_line (int argc, char ** argv) static void sim_target_parse_arg_array (char ** argv) { - int i; - - for (i = 0; argv[i]; i++) - ; - - sim_target_parse_command_line (i, argv); + sim_target_parse_command_line (countargv (argv), argv); } static sim_cia diff --git a/sim/bfin/ChangeLog b/sim/bfin/ChangeLog index fe7f6a6..ce03a80 100644 --- a/sim/bfin/ChangeLog +++ b/sim/bfin/ChangeLog @@ -1,5 +1,11 @@ 2016-01-03 Mike Frysinger + * interp.c (count_argc): Delete. + (bfin_syscall): Change count_argc to countargv. + (bfin_user_init): Likewise. + +2016-01-03 Mike Frysinger + * configure.ac (SIM_AC_OPTION_HOSTENDIAN): Delete. * configure: Regenerate. diff --git a/sim/bfin/interp.c b/sim/bfin/interp.c index 10b331f..84fb085 100644 --- a/sim/bfin/interp.c +++ b/sim/bfin/interp.c @@ -112,20 +112,6 @@ static const char cb_libgloss_stat_map_32[] = "space,4:st_blksize,4:st_blocks,4:space,8"; static const char *stat_map_32, *stat_map_64; -/* Count the number of arguments in an argv. */ -static int -count_argc (const char * const *argv) -{ - int i; - - if (! argv) - return -1; - - for (i = 0; argv[i] != NULL; ++i) - continue; - return i; -} - /* Simulate a monitor trap, put the result into r0 and errno into r1 return offset by which to adjust pc. */ @@ -180,12 +166,12 @@ bfin_syscall (SIM_CPU *cpu) #ifdef CB_SYS_argc case CB_SYS_argc: tbuf += sprintf (tbuf, "argc()"); - sc.result = count_argc (argv); + sc.result = countargv ((char **)argv); break; case CB_SYS_argnlen: { tbuf += sprintf (tbuf, "argnlen(%u)", args[0]); - if (sc.arg1 < count_argc (argv)) + if (sc.arg1 < countargv ((char **)argv)) sc.result = strlen (argv[sc.arg1]); else sc.result = -1; @@ -194,7 +180,7 @@ bfin_syscall (SIM_CPU *cpu) case CB_SYS_argn: { tbuf += sprintf (tbuf, "argn(%u)", args[0]); - if (sc.arg1 < count_argc (argv)) + if (sc.arg1 < countargv ((char **)argv)) { const char *argn = argv[sc.arg1]; int len = strlen (argn); @@ -1073,7 +1059,7 @@ bfin_user_init (SIM_DESC sd, SIM_CPU *cpu, struct bfd *abfd, sim_pc_set (cpu, elf_addrs[0]); /* Figure out how much storage the argv/env strings need. */ - argc = count_argc (argv); + argc = countargv ((char **)argv); if (argc == -1) argc = 0; argv_flat = argc; /* NUL bytes */ @@ -1082,7 +1068,7 @@ bfin_user_init (SIM_DESC sd, SIM_CPU *cpu, struct bfd *abfd, if (!env) env = simple_env; - envc = count_argc (env); + envc = countargv ((char **)env); env_flat = envc; /* NUL bytes */ for (i = 0; i < envc; ++i) env_flat += strlen (env[i]); diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index 2e444d1..e66c289 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,5 +1,10 @@ 2016-01-03 Mike Frysinger + * sim-options.c (sim_parse_args): Replace for loop with a call + to countargv. + +2016-01-03 Mike Frysinger + * nrun.c (myname): Mark const. (main): Mark name const. Replace myname parsing loop with a call to lbasename. diff --git a/sim/common/sim-options.c b/sim/common/sim-options.c index e252756..88663f7 100644 --- a/sim/common/sim-options.c +++ b/sim/common/sim-options.c @@ -474,8 +474,7 @@ sim_parse_args (SIM_DESC sd, char **argv) SIM_RC result = SIM_RC_OK; /* Count the number of arguments. */ - for (argc = 0; argv[argc] != NULL; ++argc) - continue; + argc = countargv (argv); /* Count the number of options. */ num_opts = 0; diff --git a/sim/erc32/ChangeLog b/sim/erc32/ChangeLog index d47549a..17267f4 100644 --- a/sim/erc32/ChangeLog +++ b/sim/erc32/ChangeLog @@ -1,5 +1,9 @@ 2016-01-03 Mike Frysinger + * interf.c (sim_open): Replace while loop with a call to countargv. + +2016-01-03 Mike Frysinger + * configure.ac (SIM_AC_OPTION_HOSTENDIAN): Delete. * configure: Regenerate. * exec.c (fpexec): Rename CURRENT_HOST_BYTE_ORDER to diff --git a/sim/erc32/interf.c b/sim/erc32/interf.c index bfa4f72..7f3b8df 100644 --- a/sim/erc32/interf.c +++ b/sim/erc32/interf.c @@ -171,8 +171,7 @@ sim_open (kind, callback, abfd, argv) sim_callback = callback; - while (argv[argc]) - argc++; + argc = countargv (argv); while (stat < argc) { if (argv[stat][0] == '-') { if (strcmp(argv[stat], "-v") == 0) { diff --git a/sim/sh/ChangeLog b/sim/sh/ChangeLog index 7fd3492..b3f8854 100644 --- a/sim/sh/ChangeLog +++ b/sim/sh/ChangeLog @@ -1,5 +1,10 @@ 2016-01-03 Mike Frysinger + * interp.c (count_argc): Delete. + (trap): Change count_argc to countargv. + +2016-01-03 Mike Frysinger + * configure.ac (SIM_AC_OPTION_HOSTENDIAN): Delete. * configure: Regenerate. * interp.c (host_little_endian): Change CURRENT_HOST_BYTE_ORDER diff --git a/sim/sh/interp.c b/sim/sh/interp.c index ee34e0d..f59ad00 100644 --- a/sim/sh/interp.c +++ b/sim/sh/interp.c @@ -240,20 +240,6 @@ do { \ #define FPSCR_SZ ((GET_FPSCR () & FPSCR_MASK_SZ) != 0) #define FPSCR_PR ((GET_FPSCR () & FPSCR_MASK_PR) != 0) -/* Count the number of arguments in an argv. */ -static int -count_argc (char **argv) -{ - int i; - - if (! argv) - return -1; - - for (i = 0; argv[i] != NULL; ++i) - continue; - return i; -} - static void set_fpscr1 (int x) { @@ -1056,16 +1042,16 @@ trap (SIM_DESC sd, int i, int *regs, unsigned char *insn_ptr, break; } case SYS_argc: - regs[0] = count_argc (prog_argv); + regs[0] = countargv (prog_argv); break; case SYS_argnlen: - if (regs[5] < count_argc (prog_argv)) + if (regs[5] < countargv (prog_argv)) regs[0] = strlen (prog_argv[regs[5]]); else regs[0] = -1; break; case SYS_argn: - if (regs[5] < count_argc (prog_argv)) + if (regs[5] < countargv (prog_argv)) { /* Include the termination byte. */ int i = strlen (prog_argv[regs[5]]) + 1; diff --git a/sim/sh64/ChangeLog b/sim/sh64/ChangeLog index d719c5c..82a06b0 100644 --- a/sim/sh64/ChangeLog +++ b/sim/sh64/ChangeLog @@ -1,5 +1,10 @@ 2016-01-03 Mike Frysinger + * sh64.c (count_argc): Delete. + (trap_handler): Change count_argc to countargv. + +2016-01-03 Mike Frysinger + * configure.ac (SIM_AC_OPTION_HOSTENDIAN): Delete. * configure: Regenerate. diff --git a/sim/sh64/sh64.c b/sim/sh64/sh64.c index c35b5c1..e239625 100644 --- a/sim/sh64/sh64.c +++ b/sim/sh64/sh64.c @@ -529,22 +529,6 @@ sh64_pref (SIM_CPU *cpu, SI addr) /* TODO: Unimplemented. */ } -/* Count the number of arguments. */ -static int -count_argc (cpu) - SIM_CPU *cpu; -{ - int i = 0; - - if (! STATE_PROG_ARGV (CPU_STATE (cpu))) - return -1; - - while (STATE_PROG_ARGV (CPU_STATE (cpu)) [i] != NULL) - ++i; - - return i; -} - /* Read a null terminated string from memory, return in a buffer */ static char * fetch_str (current_cpu, pc, addr) @@ -634,11 +618,11 @@ trap_handler (SIM_CPU *current_cpu, int shmedia_abi_p, UQI trapnum, PCADDR pc) break; case SYS_argc: - SET_H_GR (ret_reg, count_argc (current_cpu)); + SET_H_GR (ret_reg, countargv (STATE_PROG_ARGV (CPU_STATE (current_cpu)))); break; case SYS_argnlen: - if (PARM1 < count_argc (current_cpu)) + if (PARM1 < countargv (STATE_PROG_ARGV (CPU_STATE (current_cpu)))) SET_H_GR (ret_reg, strlen (STATE_PROG_ARGV (CPU_STATE (current_cpu)) [PARM1])); else @@ -646,7 +630,7 @@ trap_handler (SIM_CPU *current_cpu, int shmedia_abi_p, UQI trapnum, PCADDR pc) break; case SYS_argn: - if (PARM1 < count_argc (current_cpu)) + if (PARM1 < countargv (STATE_PROG_ARGV (CPU_STATE (current_cpu)))) { /* Include the NULL byte. */ i = strlen (STATE_PROG_ARGV (CPU_STATE (current_cpu)) [PARM1]) + 1;