[binutils-gdb] gcore: Remove bashisms and use POSIX sh

Simon Marchi simark@sourceware.org
Tue Oct 14 04:46:24 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a8a65f0dc7d90eb4061ab382e302f768abfbe717

commit a8a65f0dc7d90eb4061ab382e302f768abfbe717
Author: Natanael Copa <ncopa@alpinelinux.org>
Date:   Thu Oct 9 13:15:34 2025 +0200

    gcore: Remove bashisms and use POSIX sh
    
    - Switch script shebang to /bin/sh
    - Remove unnecessary `function` keywords
    - Replace bash arrays with simple scalar variables
    - Use $(uname -s) instead of bash specific $OSINFO
    
    Approved-By: Simon Marchi <simon.marchi@efficios.com>

Diff:
---
 gdb/gcore-1.in | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/gdb/gcore-1.in b/gdb/gcore-1.in
index fe2bb3d650a..28f633e57ad 100755
--- a/gdb/gcore-1.in
+++ b/gdb/gcore-1.in
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/sh
 
 #   Copyright (C) 2003-2025 Free Software Foundation, Inc.
 
@@ -28,14 +28,15 @@ prefix=core
 
 # When the -a option is present, this may hold additional commands
 # to ensure gdb dumps all mappings (OS dependent).
-dump_all_cmds=()
+use_coredump_filter=
+dump_excluded_mappings=
 
-data_directory_opt=()
+data_directory=
 
 # The GDB binary to run.
 gdb_binary=
 
-function print_usage() {
+print_usage() {
     prefix="Usage: $0"
     padding=$(printf '%*s' ${#prefix})
 
@@ -44,11 +45,11 @@ function print_usage() {
     echo "$padding pid1 [pid2...pidN]"
 }
 
-function print_try_help() {
+print_try_help() {
     echo "Try '$0 --help' for more information."
 }
 
-function print_help() {
+print_help() {
     print_usage
     echo
     echo "Create a core file of a running program using GDB."
@@ -64,7 +65,7 @@ function print_help() {
     echo "                       to GDB."
 }
 
-function print_version() {
+print_version() {
     echo "GNU gcore (${PKGVERSION}) ${VERSION}"
 }
 
@@ -77,10 +78,10 @@ while getopts vhao:g:d:-: OPT; do
 
     case "$OPT" in
         a)
-            case "$OSTYPE" in
-                linux*)
-                    dump_all_cmds=("-ex" "set use-coredump-filter off")
-                    dump_all_cmds+=("-ex" "set dump-excluded-mappings on")
+            case "$(uname -s)" in
+                Linux)
+                    use_coredump_filter="off"
+                    dump_excluded_mappings="on"
                     ;;
             esac
             ;;
@@ -91,7 +92,7 @@ while getopts vhao:g:d:-: OPT; do
             gdb_binary="$OPTARG"
             ;;
         d)
-            data_directory_opt=("--data-directory" "$OPTARG")
+            data_directory="$OPTARG"
             ;;
 	h | help)
 	    print_help
@@ -174,10 +175,11 @@ do
 	# `</dev/null' to avoid touching interactive terminal if it is
 	# available but not accessible as GDB would get stopped on SIGTTIN.
 	"$gdb_binary" </dev/null \
-            "${data_directory_opt[@]}" \
+            ${data_directory:+--data-directory "$data_directory"} \
 	    --nx --batch --readnever -iex 'set debuginfod enabled off' \
 	    -ex "set pagination off" -ex "set height 0" -ex "set width 0" \
-	    "${dump_all_cmds[@]}" \
+            ${use_coredump_filter:+-ex "set use-coredump-filter ${use_coredump_filter}"} \
+	    ${dump_excluded_mappings:+-ex "set dump-excluded-mappings ${dump_excluded_mappings}"} \
 	    -ex "attach $pid" -ex "gcore $prefix.$pid" -ex detach -ex quit
 
 	if [ -r "$prefix.$pid" ] ; then


More information about the Gdb-cvs mailing list