[PATCH 3/4] Add "-a" argument to gcore.in

Sergio Lopez
2017-11-28T13:22:21Z

The new "-a" argument instructs the gcore script to disable both
use-coredump-filter and honor-dontdump-flag before generating the core
file.

This allows the user to unconditionally dump all memory regions,
mimicking the behavior of previous gdb/gcore versions (before support
for coredump_filter was implemented).

2017-11-28 Sergio Lopez <slp@redhat.com>
* gcore.in: Add "-a" argument for disabling both
use-coredump-filter and honor-dontdump-flag.
---
gdb/ChangeLog | 4 ++++
gdb/gcore.in | 25 +++++++++++++++++++++++--
2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ce68fee776..ba8826c84c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2017-11-28 Sergio Lopez <slp@redhat.com>
+ * gcore.in: Add "-a" argument for disabling both
+ use-coredump-filter and honor-dontdump-flag.
+
2017-11-28 Sergio Lopez <slp@redhat.com>

* linux-tdep.c (honor_dontdump_flag): New variable.
diff --git a/gdb/gcore.in b/gdb/gcore.in
index 632f21bdfa..32e597dc4f 100644
--- a/gdb/gcore.in
+++ b/gdb/gcore.in
@@ -22,10 +22,29 @@

if [ "$#" -eq "0" ]
then
- echo "usage: @GCORE_TRANSFORM_NAME@ [-o filename] pid"
+ echo "usage: @GCORE_TRANSFORM_NAME@ [-a] [-o filename] pid"
exit 2
fi

+# Check for -a option, default to honor coredump_filter and VM_DONTDUMP.
+use_coredump_filter=on
+honor_dontdump_flag=on
+
+if [ "$1" = "-a" ]
+then
+ if [ "$#" -lt "2" ]
+ then
+ # Not enough arguments.
+ echo "usage: @GCORE_TRANSFORM_NAME@ [-a] [-o filename] pid"
+ exit 2
+ fi
+ use_coredump_filter=off
+ honor_dontdump_flag=off
+
+ # Shift over to the next argument
+ shift;
+fi
+
# Need to check for -o option, but set default basename to "core".
name=core

@@ -34,7 +53,7 @@ then
if [ "$#" -lt "3" ]
then
# Not enough arguments.
- echo "usage: @GCORE_TRANSFORM_NAME@ [-o filename] pid"
+ echo "usage: @GCORE_TRANSFORM_NAME@ [-a] [-o filename] pid"
exit 2
fi
name=$2
@@ -87,6 +106,8 @@ do
# available but not accessible as GDB would get stopped on SIGTTIN.
$binary_path/@GDB_TRANSFORM_NAME@ </dev/null --nx --batch \
-ex "set pagination off" -ex "set height 0" -ex "set width 0" \
+ -ex "set use-coredump-filter $use_coredump_filter" \
+ -ex "set honor-dontdump-flag $honor_dontdump_flag" \
-ex "attach $pid" -ex "gcore $name.$pid" -ex detach -ex quit

if [ -r $name.$pid ] ; then
--
2.14.3