Blame SOURCES/gdb-rhbz1518243-gcore-VM_DONTDUMP-3of5.patch

01917d
commit cd93789b89f55355d3eeda6c31ed7bd0ed318acd
01917d
Author: Sergio Lopez <slp@redhat.com>
01917d
Date:   Mon Dec 4 09:17:14 2017 +0100
01917d
01917d
    Implement "-a" command line option for gcore
01917d
    
01917d
    With the new "-a" command line option, the user may request gcore to
01917d
    actually dump all present memory mappings. The actual effect of this
01917d
    argument is OS dependent.
01917d
    
01917d
    On GNU/Linux, it will disable use-coredump-filter and enable
01917d
    dump-excluded-mappings.
01917d
    
01917d
    gdb/ChangeLog:
01917d
    2017-11-29  Sergio Lopez  <slp@redhat.com>
01917d
    
01917d
            * gcore.in: Add "-a" command line option for instructing gdb to
01917d
            dump all memory mappings (OS dependent).
01917d
01917d
Index: gdb-7.6.1/gdb/gcore.in
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/gcore.in	2017-12-06 20:57:13.444335680 +0100
01917d
+++ gdb-7.6.1/gdb/gcore.in	2017-12-06 20:57:20.437380926 +0100
01917d
@@ -20,27 +20,39 @@
01917d
 # It starts up gdb, attaches to the given PID and invokes the gcore command.
01917d
 #
01917d
 
01917d
-if [ "$#" -eq "0" ]
01917d
-then
01917d
-    echo "usage:  @GCORE_TRANSFORM_NAME@ [-o filename] pid"
01917d
-    exit 2
01917d
-fi
01917d
-
01917d
 # Need to check for -o option, but set default basename to "core".
01917d
 name=core
01917d
 
01917d
-if [ "$1" = "-o" ]
01917d
-then
01917d
-    if [ "$#" -lt "3" ]
01917d
-    then
01917d
-	# Not enough arguments.
01917d
-	echo "usage:  @GCORE_TRANSFORM_NAME@ [-o filename] pid"
01917d
-	exit 2
01917d
-    fi
01917d
-    name=$2
01917d
+# When the -a option is present, this may hold additional commands
01917d
+# to ensure gdb dumps all mappings (OS dependent).
01917d
+dump_all_cmds=()
01917d
+
01917d
+while getopts :ao: opt; do
01917d
+    case $opt in
01917d
+        a)
01917d
+            case $OSTYPE in
01917d
+                linux*)
01917d
+                    dump_all_cmds=("-ex" "set use-coredump-filter off")
01917d
+                    dump_all_cmds+=("-ex" "set dump-excluded-mappings on")
01917d
+                    ;;
01917d
+            esac
01917d
+            ;;
01917d
+        o)
01917d
+            name=$OPTARG
01917d
+            ;;
01917d
+        *)
01917d
+            echo "usage:  @GCORE_TRANSFORM_NAME@ [-a] [-o filename] pid"
01917d
+            exit 2
01917d
+            ;;
01917d
+    esac
01917d
+done
01917d
+
01917d
+shift $((OPTIND-1))
01917d
 
01917d
-    # Shift over to start of pid list
01917d
-    shift; shift
01917d
+if [ "$#" -eq "0" ]
01917d
+then
01917d
+    echo "usage:  @GCORE_TRANSFORM_NAME@ [-a] [-o filename] pid"
01917d
+    exit 2
01917d
 fi
01917d
 
01917d
 # Initialise return code.
01917d
@@ -53,6 +65,7 @@
01917d
 	# available but not accessible as GDB would get stopped on SIGTTIN.
01917d
 	@GDB_TRANSFORM_NAME@ 
01917d
 	    -ex "set pagination off" -ex "set height 0" -ex "set width 0" \
01917d
+	    "${dump_all_cmds[@]}" \
01917d
 	    -ex "attach $pid" -ex "gcore $name.$pid" -ex detach -ex quit
01917d
 
01917d
 	if [ -r $name.$pid ] ; then