public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] Enable the user to dump all memory regions
@ 2017-11-29 10:55 Sergio Lopez
  2017-11-29 10:55 ` [PATCH v2 2/4] Document new {set,show} dump-excluded-mappings commands Sergio Lopez
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Sergio Lopez @ 2017-11-29 10:55 UTC (permalink / raw)
  To: gdb-patches; +Cc: Sergio Lopez

Thanks for all the feedback received for this patchset. This second
version should address all the issues found in v1. Please let me know if
you still find something that can be improved.

=============

GDB versions prior to df8411da087dc05481926f4c4a82deabc5bc3859
unconditionally included all memory regions in the core dump.

After that change, while is still possible to ask GDB to ignore
/proc/PID/coredump_filter using the 'set use-coredump-filter' command,
there's no way to request it to dump regions marked with the VM_DONTDUMP
flag ("dd" in /proc/PID/smaps").

This patch series implement the new 'set honor-dontdump-flag' command
for GDB, and the "-a" argument for gcore, allowing the user to mimic the
behavior of previous GDB versions.

Sergio Lopez (4):
  Implement 'set dump-excluded-mappings' command
  Document new {set,show} dump-excluded-mappings commands.
  Implement "-a" command line option for gcore
  Document the new "-a" command line option for gcore

 gdb/NEWS            | 10 ++++++++++
 gdb/doc/gdb.texinfo | 21 +++++++++++++++++++--
 gdb/gcore.in        | 47 ++++++++++++++++++++++++++++++-----------------
 gdb/linux-tdep.c    | 31 ++++++++++++++++++++++++++++++-
 4 files changed, 89 insertions(+), 20 deletions(-)

-- 
2.14.3

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 2/4] Document new {set,show} dump-excluded-mappings commands.
  2017-11-29 10:55 [PATCH v2 0/4] Enable the user to dump all memory regions Sergio Lopez
@ 2017-11-29 10:55 ` Sergio Lopez
  2017-11-29 17:40   ` Eli Zaretskii
  2017-11-29 10:56 ` [PATCH v2 3/4] Implement "-a" command line option for gcore Sergio Lopez
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Sergio Lopez @ 2017-11-29 10:55 UTC (permalink / raw)
  To: gdb-patches; +Cc: Sergio Lopez

gdb/ChangeLog:
2017-11-29  Sergio Lopez  <slp@redhat.com>

	* NEWS (Changes since GDB 8.0): Announce {set,show}
	dump_excluded_mappings commands.

gdb/doc/ChangeLog:
2017-11-29  Sergio Lopez  <slp@redhat.com>

	* gdb.texinfo (gcore): Mention new {set,show}
	dump-excluded-mappings commands.
	(set dump-excluded-mappings): Document new command.
---
 gdb/NEWS            |  5 +++++
 gdb/doc/gdb.texinfo | 14 +++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 754ce103bd..1372552a37 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -134,6 +134,11 @@ set debug separate-debug-file
 show debug separate-debug-file
   Control the display of debug output about separate debug file search.
 
+set dump-excluded-mappings
+show dump-excluded-mappings
+  Control whether mappings marked with the VM_DONTDUMP flag should be
+  dumped when generating a core file.
+
 maint info selftests
   List the registered selftests.
 
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 675f6e7bc8..7b25912e49 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -11543,7 +11543,9 @@ this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
 
 On @sc{gnu}/Linux, this command can take into account the value of the
 file @file{/proc/@var{pid}/coredump_filter} when generating the core
-dump (@pxref{set use-coredump-filter}).
+dump (@pxref{set use-coredump-filter}), and by default honors the
+@code{VM_DONTDUMP} flag for mappings where it is present in the file
+@file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
 
 @kindex set use-coredump-filter
 @anchor{set use-coredump-filter}
@@ -11573,6 +11575,16 @@ value is currently @code{0x33}, which means that bits @code{0}
 (anonymous private mappings), @code{1} (anonymous shared mappings),
 @code{4} (ELF headers) and @code{5} (private huge pages) are active.
 This will cause these memory mappings to be dumped automatically.
+
+@kindex set dump-excluded-mappings
+@anchor{set dump-excluded-mappings}
+@item set dump-excluded-mappings on
+@itemx set dump-excluded-mappings off
+If @code{on} is specified, @value{GDBN} will dump memory mappings
+marked with the @code{VM_DONTDUMP} flag.  This flag is represented in
+the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
+
+The default value is @code{off}.
 @end table
 
 @node Character Sets
-- 
2.14.3

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 4/4] Document the new "-a" command line option for gcore
  2017-11-29 10:55 [PATCH v2 0/4] Enable the user to dump all memory regions Sergio Lopez
                   ` (2 preceding siblings ...)
  2017-11-29 10:56 ` [PATCH v2 1/4] Implement 'set dump-excluded-mappings' command Sergio Lopez
@ 2017-11-29 10:56 ` Sergio Lopez
  2017-11-29 17:41   ` Eli Zaretskii
  3 siblings, 1 reply; 7+ messages in thread
From: Sergio Lopez @ 2017-11-29 10:56 UTC (permalink / raw)
  To: gdb-patches; +Cc: Sergio Lopez

gdb/ChangeLog:
2017-11-29  Sergio Lopez  <slp@redhat.com>

	* NEWS (Changes since GDB 8.0): Announce new "-a"
	command line option for gcore.

gdb/doc/ChangeLog:
2017-11-29  Sergio Lopez  <slp@redhat.com>

	* gdb.texinfo (gcore man): Document new "-a" command line option.
---
 gdb/NEWS            | 5 +++++
 gdb/doc/gdb.texinfo | 7 ++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 1372552a37..ce84fe7924 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -52,6 +52,11 @@
 
   ** The "complete" command now mimics TAB completion accurately.
 
+* New command line options (gcore)
+
+-a
+  Dump all memory mappings.
+
 * Python Scripting
 
   ** New events gdb.new_inferior, gdb.inferior_deleted, and
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 7b25912e49..88d6820998 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -42948,7 +42948,7 @@ Richard M. Stallman and Roland H. Pesch, July 1991.
 
 @format
 @c man begin SYNOPSIS gcore
-gcore [-o @var{filename}] @var{pid}
+gcore [-a] [-o @var{filename}] @var{pid}
 @c man end
 @end format
 
@@ -42962,6 +42962,11 @@ running without any change.
 
 @c man begin OPTIONS gcore
 @table @env
+@item -a
+Dump all memory mappings.  The actual effect of this option depends on the
+Operating System.  On @sc{gnu}/Linux, it will disable
+@code{use-coredump-filter} and enable @code{dump-excluded-mappings}.
+
 @item -o @var{filename}
 The optional argument
 @var{filename} specifies the file name where to put the core dump.
-- 
2.14.3

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/4] Implement 'set dump-excluded-mappings' command
  2017-11-29 10:55 [PATCH v2 0/4] Enable the user to dump all memory regions Sergio Lopez
  2017-11-29 10:55 ` [PATCH v2 2/4] Document new {set,show} dump-excluded-mappings commands Sergio Lopez
  2017-11-29 10:56 ` [PATCH v2 3/4] Implement "-a" command line option for gcore Sergio Lopez
@ 2017-11-29 10:56 ` Sergio Lopez
  2017-11-29 10:56 ` [PATCH v2 4/4] Document the new "-a" command line option for gcore Sergio Lopez
  3 siblings, 0 replies; 7+ messages in thread
From: Sergio Lopez @ 2017-11-29 10:56 UTC (permalink / raw)
  To: gdb-patches; +Cc: Sergio Lopez

Commit df8411da087dc05481926f4c4a82deabc5bc3859 implemented support for
checking /proc/PID/coredump_filter, and also changed gcore behavior to
unconditionally honor the VM_DONTDUMP flag, preventing sections marked
as such for being dumped into the core file.

This patch implements the 'set dump-excluded-mappings' command for
instructing gdb to ignore the VM_DONTDUMP flag. Combined with 'set
use-coredump-filter', this allows the user to restore the old behavior,
dumping all sections (except the ones marked as IO) unconditionally.

gdb/Changelog:
2017-11-29  Sergio Lopez  <slp@redhat.com>

	* linux-tdep.c (dump_excluded_mappings): New variable.
	(dump_mapping_p): Use dump_excluded_mappings variable.
	(_initialize_linux_tdep): New command 'set dump_excluded_mappings'.
---
 gdb/linux-tdep.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 24237b8d39..e458398137 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -93,6 +93,12 @@ struct smaps_vmflags
 
 static int use_coredump_filter = 1;
 
+/* Whether the value of smaps_vmflags->exclude_coredump should be
+   ignored, including mappings marked with the VM_DONTDUMP flag in
+   the dump.  */
+
+static int dump_excluded_mappings = 0;
+
 /* This enum represents the signals' numbers on a generic architecture
    running the Linux kernel.  The definition of "generic" comes from
    the file <include/uapi/asm-generic/signal.h>, from the Linux kernel
@@ -655,7 +661,7 @@ dump_mapping_p (filter_flags filterflags, const struct smaps_vmflags *v,
 	return 0;
 
       /* Check if we should exclude this mapping.  */
-      if (v->exclude_coredump)
+      if (!dump_excluded_mappings && v->exclude_coredump)
 	return 0;
 
       /* Update our notion of whether this mapping is shared or
@@ -2469,6 +2475,17 @@ show_use_coredump_filter (struct ui_file *file, int from_tty,
 			    " corefiles is %s.\n"), value);
 }
 
+/* Display whether the gcore command is dumping mappings marked with
+   the VM_DONTDUMP flag.  */
+
+static void
+show_dump_excluded_mappings (struct ui_file *file, int from_tty,
+			     struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Dumping of mappings marked with the VM_DONTDUMP"
+			    " flag is %s.\n"), value);
+}
+
 /* To be called from the various GDB_OSABI_LINUX handlers for the
    various GNU/Linux architectures and machine types.  */
 
@@ -2517,4 +2534,16 @@ of /proc/PID/coredump_filter when generating the corefile.  For more information
 about this file, refer to the manpage of core(5)."),
 			   NULL, show_use_coredump_filter,
 			   &setlist, &showlist);
+
+  add_setshow_boolean_cmd ("dump-excluded-mappings", class_files,
+			   &dump_excluded_mappings, _("\
+Set whether gcore should dump mappings marked with the VM_DONTDUMP flag."),
+			   _("\
+Show whether gcore should dump mappings marked with the VM_DONTDUMP flag."),
+			   _("\
+Use this command to set whether gcore should dump mappings marked with the\n\
+VM_DONTDUMP flag (\"dd\" in /proc/PID/smaps) when generating the corefile.  For\n\
+more information about this file, refer to the manpage of proc(5) and core(5)."),
+			   NULL, show_dump_excluded_mappings,
+			   &setlist, &showlist);
 }
-- 
2.14.3

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 3/4] Implement "-a" command line option for gcore
  2017-11-29 10:55 [PATCH v2 0/4] Enable the user to dump all memory regions Sergio Lopez
  2017-11-29 10:55 ` [PATCH v2 2/4] Document new {set,show} dump-excluded-mappings commands Sergio Lopez
@ 2017-11-29 10:56 ` Sergio Lopez
  2017-11-29 10:56 ` [PATCH v2 1/4] Implement 'set dump-excluded-mappings' command Sergio Lopez
  2017-11-29 10:56 ` [PATCH v2 4/4] Document the new "-a" command line option for gcore Sergio Lopez
  3 siblings, 0 replies; 7+ messages in thread
From: Sergio Lopez @ 2017-11-29 10:56 UTC (permalink / raw)
  To: gdb-patches; +Cc: Sergio Lopez

With the new "-a" command line option, the user may request gcore to
actually dump all present memory mappings. The actual effect of this
argument is OS dependent.

On GNU/Linux, it will disable use-coredump-filter and enable
dump-excluded-mappings.

gdb/ChangeLog:
2017-11-29  Sergio Lopez  <slp@redhat.com>

	* gcore.in: Add "-a" command line option for instructing gdb to
	dump all memory mappings (OS dependent).
---
 gdb/gcore.in | 47 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 30 insertions(+), 17 deletions(-)

diff --git a/gdb/gcore.in b/gdb/gcore.in
index 632f21bdfa..44b2e98b27 100644
--- a/gdb/gcore.in
+++ b/gdb/gcore.in
@@ -20,27 +20,39 @@
 # It starts up gdb, attaches to the given PID and invokes the gcore command.
 #
 
-if [ "$#" -eq "0" ]
-then
-    echo "usage:  @GCORE_TRANSFORM_NAME@ [-o filename] pid"
-    exit 2
-fi
-
 # Need to check for -o option, but set default basename to "core".
 name=core
 
-if [ "$1" = "-o" ]
+# When the -a option is present, this may hold additional commands
+# to ensure gdb dumps all mappings (OS dependent).
+dump_all_cmds=()
+
+while getopts :ao: 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")
+                    ;;
+            esac
+            ;;
+        o)
+            name=$OPTARG
+            ;;
+        *)
+            echo "usage:  @GCORE_TRANSFORM_NAME@ [-a] [-o filename] pid"
+            exit 2
+            ;;
+    esac
+done
+
+shift $((OPTIND-1))
+
+if [ "$#" -eq "0" ]
 then
-    if [ "$#" -lt "3" ]
-    then
-	# Not enough arguments.
-	echo "usage:  @GCORE_TRANSFORM_NAME@ [-o filename] pid"
-	exit 2
-    fi
-    name=$2
-
-    # Shift over to start of pid list
-    shift; shift
+    echo "usage:  @GCORE_TRANSFORM_NAME@ [-a] [-o filename] pid"
+    exit 2
 fi
 
 # Attempt to fetch the absolute path to the gcore script that was
@@ -87,6 +99,7 @@ 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" \
+	    "${dump_all_cmds[@]}" \
 	    -ex "attach $pid" -ex "gcore $name.$pid" -ex detach -ex quit
 
 	if [ -r $name.$pid ] ; then 
-- 
2.14.3

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/4] Document new {set,show} dump-excluded-mappings commands.
  2017-11-29 10:55 ` [PATCH v2 2/4] Document new {set,show} dump-excluded-mappings commands Sergio Lopez
@ 2017-11-29 17:40   ` Eli Zaretskii
  0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2017-11-29 17:40 UTC (permalink / raw)
  To: Sergio Lopez; +Cc: gdb-patches

> From: Sergio Lopez <slp@redhat.com>
> Cc: Sergio Lopez <slp@redhat.com>
> Date: Wed, 29 Nov 2017 11:55:41 +0100
> 
> gdb/ChangeLog:
> 2017-11-29  Sergio Lopez  <slp@redhat.com>
> 
> 	* NEWS (Changes since GDB 8.0): Announce {set,show}
> 	dump_excluded_mappings commands.
> 
> gdb/doc/ChangeLog:
> 2017-11-29  Sergio Lopez  <slp@redhat.com>
> 
> 	* gdb.texinfo (gcore): Mention new {set,show}
> 	dump-excluded-mappings commands.
> 	(set dump-excluded-mappings): Document new command.

OK.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 4/4] Document the new "-a" command line option for gcore
  2017-11-29 10:56 ` [PATCH v2 4/4] Document the new "-a" command line option for gcore Sergio Lopez
@ 2017-11-29 17:41   ` Eli Zaretskii
  0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2017-11-29 17:41 UTC (permalink / raw)
  To: Sergio Lopez; +Cc: gdb-patches

> From: Sergio Lopez <slp@redhat.com>
> Cc: Sergio Lopez <slp@redhat.com>
> Date: Wed, 29 Nov 2017 11:55:43 +0100
> 
> gdb/ChangeLog:
> 2017-11-29  Sergio Lopez  <slp@redhat.com>
> 
> 	* NEWS (Changes since GDB 8.0): Announce new "-a"
> 	command line option for gcore.
> 
> gdb/doc/ChangeLog:
> 2017-11-29  Sergio Lopez  <slp@redhat.com>
> 
> 	* gdb.texinfo (gcore man): Document new "-a" command line option.

Thanks, this is OK.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-11-29 17:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-29 10:55 [PATCH v2 0/4] Enable the user to dump all memory regions Sergio Lopez
2017-11-29 10:55 ` [PATCH v2 2/4] Document new {set,show} dump-excluded-mappings commands Sergio Lopez
2017-11-29 17:40   ` Eli Zaretskii
2017-11-29 10:56 ` [PATCH v2 3/4] Implement "-a" command line option for gcore Sergio Lopez
2017-11-29 10:56 ` [PATCH v2 1/4] Implement 'set dump-excluded-mappings' command Sergio Lopez
2017-11-29 10:56 ` [PATCH v2 4/4] Document the new "-a" command line option for gcore Sergio Lopez
2017-11-29 17:41   ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).