* [PATCH 1/3] gcore: add -v or --version option to show version number
2025-03-06 17:10 [PATCH 0/3] gcore: add --help and --version options Andrew Burgess
@ 2025-03-06 17:10 ` Andrew Burgess
2025-03-06 17:31 ` Eli Zaretskii
2025-03-06 17:10 ` [PATCH 2/3] gcore: add -h|--help options, and improve help/usage message output Andrew Burgess
` (3 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Andrew Burgess @ 2025-03-06 17:10 UTC (permalink / raw)
To: gdb-patches; +Cc: Andrew Burgess
Based on the work in this commit:
commit fb2ded33c1e519659743047ed7817166545b6d91
Date: Fri Dec 20 12:46:11 2024 -0800
Add gstack script
This commit adds a '-v' or '--version' option to the existing gcore
script. This new option causes the script to print its version
number, and then exit.
I needed to adjust the getopts handling a little in order to support
the long form '--version' argument, but as this makes gcore more
consistent with gstack, then this seems like a good thing.
The usage message is now getting a little long. Don't worry, I plan
to clean that up in the next commit.
---
gdb/Makefile.in | 7 ++-----
gdb/NEWS | 3 +++
gdb/configure | 5 ++---
gdb/configure.ac | 2 +-
gdb/doc/gdb.texinfo | 7 ++++++-
gdb/{gcore.in => gcore-1.in} | 23 ++++++++++++++++++++---
6 files changed, 34 insertions(+), 13 deletions(-)
rename gdb/{gcore.in => gcore-1.in} (88%)
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 1619c8253dc..a87e9520ffe 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -2347,18 +2347,15 @@ run: Makefile
jit-reader.h: $(srcdir)/jit-reader.in config.status
$(ECHO_GEN) $(SHELL) config.status $(SILENT_FLAG) $@
-gcore: $(srcdir)/gcore.in config.status
+gstack.in gcore.in: %.in : $(srcdir)/%-1.in config.status
$(ECHO_GEN) $(SHELL) config.status $(SILENT_FLAG) $@
-gstack: gstack.in version.c
+gstack gcore: % : %.in version.c
$(ECHO_GEN) \
vv=`grep 'version\[\] = ' version.c | grep -o '".*"' | tr -d \"`; \
sed -e "s,@VERSION@,$$vv," $< > $@
@chmod +x $@
-gstack.in: $(srcdir)/gstack-1.in config.status
- $(ECHO_GEN) $(SHELL) config.status $(SILENT_FLAG) $@
-
gdb-gdb.py: $(srcdir)/gdb-gdb.py.in config.status
$(ECHO_GEN) $(SHELL) config.status $(SILENT_FLAG) $@
diff --git a/gdb/NEWS b/gdb/NEWS
index f5dbf5c3350..d4453914755 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -26,6 +26,9 @@
* Linux checkpoint code has been updated to work with multiple inferiors.
+* The gcore script now has a -v or --version option, which prints the
+ version number, and then exits.
+
* New commands
maintenance check psymtabs
diff --git a/gdb/configure b/gdb/configure
index bdc405e01b3..3e990064197 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -33775,7 +33775,7 @@ fi
fi
-ac_config_files="$ac_config_files gcore"
+ac_config_files="$ac_config_files gcore.in:gcore-1.in"
ac_config_files="$ac_config_files gstack.in:gstack-1.in"
@@ -34878,7 +34878,7 @@ do
"default-1") CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;;
"jit-reader.h") CONFIG_FILES="$CONFIG_FILES jit-reader.h:jit-reader.in" ;;
"nm.h") CONFIG_LINKS="$CONFIG_LINKS nm.h:$GDB_NM_FILE" ;;
- "gcore") CONFIG_FILES="$CONFIG_FILES gcore" ;;
+ "gcore.in") CONFIG_FILES="$CONFIG_FILES gcore.in:gcore-1.in" ;;
"gstack.in") CONFIG_FILES="$CONFIG_FILES gstack.in:gstack-1.in" ;;
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
"gdb-gdb.gdb") CONFIG_FILES="$CONFIG_FILES gdb-gdb.gdb" ;;
@@ -36425,7 +36425,6 @@ _LT_EOF
esac
done ;;
"nm.h":L) echo > stamp-nmh ;;
- "gcore":F) chmod +x gcore ;;
esac
done # for ac_tag
diff --git a/gdb/configure.ac b/gdb/configure.ac
index fb77e79e73b..4604a2d8e87 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -2278,7 +2278,7 @@ GDB_AC_SELFTEST([
GDB_AC_TRANSFORM([gdb], [GDB_TRANSFORM_NAME])
GDB_AC_TRANSFORM([gcore], [GCORE_TRANSFORM_NAME])
-AC_CONFIG_FILES([gcore], [chmod +x gcore])
+AC_CONFIG_FILES([gcore.in:gcore-1.in])
AC_CONFIG_FILES([gstack.in:gstack-1.in])
AC_CONFIG_FILES([Makefile gdb-gdb.gdb gdb-gdb.py doc/Makefile data-directory/Makefile])
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 29c0118dda2..1ab87dd37f9 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -51386,7 +51386,8 @@ gcore man
@format
@c man begin SYNOPSIS gcore
-gcore [-a] [-o @var{prefix}] [-d @var{directory}] @var{pid1} [@var{pid2}...@var{pidN}]
+gcore [-v | --version] [-a] [-o @var{prefix}] [-d @var{directory}]
+ @var{pid1} [@var{pid2}...@var{pidN}]
@c man end
@end format
@@ -51418,6 +51419,10 @@ gcore man
@item -d @var{directory}
Use @var{directory} as the data directory when invoking @value{GDBN} for running
the gcore command. This argument is optional.
+
+@item --version
+@itemx -v
+Print version information and then exit.
@end table
@c man end
diff --git a/gdb/gcore.in b/gdb/gcore-1.in
similarity index 88%
rename from gdb/gcore.in
rename to gdb/gcore-1.in
index 0c40e5a54cd..ce2f7321148 100644
--- a/gdb/gcore.in
+++ b/gdb/gcore-1.in
@@ -20,6 +20,9 @@
# It starts up gdb, attaches to the given PID and invokes the gcore command.
#
+PKGVERSION=@PKGVERSION@
+VERSION=@VERSION@
+
# Need to check for -o option, but set default basename to "core".
prefix=core
@@ -29,8 +32,18 @@ dump_all_cmds=()
data_directory_opt=()
-while getopts :ao:d: opt; do
- case "$opt" in
+function print_version() {
+ echo "GNU gcore (${PKGVERSION}) ${VERSION}"
+}
+
+while getopts :vao:d:-: OPT; do
+ if [ "$OPT" = "-" ]; then
+ OPT="${OPTARG%%=*}"
+ OPTARG="${OPTARG#'$OPT'}"
+ OPTARG="${OPTARG#=}"
+ fi
+
+ case "$OPT" in
a)
case "$OSTYPE" in
linux*)
@@ -45,8 +58,12 @@ while getopts :ao:d: opt; do
d)
data_directory_opt=("--data-directory" "$OPTARG")
;;
+ v | version)
+ print_version
+ exit 0
+ ;;
*)
- echo "usage: @GCORE_TRANSFORM_NAME@ [-a] [-o prefix] [-d data-directory] pid1 [pid2...pidN]"
+ echo "usage: @GCORE_TRANSFORM_NAME@ [-v | --version] [-a] [-o prefix] [-d data-directory] pid1 [pid2...pidN]"
exit 2
;;
esac
--
2.47.1
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 1/3] gcore: add -v or --version option to show version number
2025-03-06 17:10 ` [PATCH 1/3] gcore: add -v or --version option to show version number Andrew Burgess
@ 2025-03-06 17:31 ` Eli Zaretskii
0 siblings, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2025-03-06 17:31 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches
> From: Andrew Burgess <aburgess@redhat.com>
> Cc: Andrew Burgess <aburgess@redhat.com>
> Date: Thu, 6 Mar 2025 17:10:22 +0000
>
> Based on the work in this commit:
>
> commit fb2ded33c1e519659743047ed7817166545b6d91
> Date: Fri Dec 20 12:46:11 2024 -0800
>
> Add gstack script
>
> This commit adds a '-v' or '--version' option to the existing gcore
> script. This new option causes the script to print its version
> number, and then exit.
>
> I needed to adjust the getopts handling a little in order to support
> the long form '--version' argument, but as this makes gcore more
> consistent with gstack, then this seems like a good thing.
>
> The usage message is now getting a little long. Don't worry, I plan
> to clean that up in the next commit.
> ---
> gdb/Makefile.in | 7 ++-----
> gdb/NEWS | 3 +++
> gdb/configure | 5 ++---
> gdb/configure.ac | 2 +-
> gdb/doc/gdb.texinfo | 7 ++++++-
> gdb/{gcore.in => gcore-1.in} | 23 ++++++++++++++++++++---
> 6 files changed, 34 insertions(+), 13 deletions(-)
> rename gdb/{gcore.in => gcore-1.in} (88%)
Thanks, the documentation parts are okay.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/3] gcore: add -h|--help options, and improve help/usage message output
2025-03-06 17:10 [PATCH 0/3] gcore: add --help and --version options Andrew Burgess
2025-03-06 17:10 ` [PATCH 1/3] gcore: add -v or --version option to show version number Andrew Burgess
@ 2025-03-06 17:10 ` Andrew Burgess
2025-03-06 17:33 ` Eli Zaretskii
2025-03-06 17:10 ` [PATCH 3/3] gcore/doc: fix mistake in the gcore man page Andrew Burgess
` (2 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Andrew Burgess @ 2025-03-06 17:10 UTC (permalink / raw)
To: gdb-patches; +Cc: Andrew Burgess
Like the previous commit, this copies a lot from:
commit fb2ded33c1e519659743047ed7817166545b6d91
Date: Fri Dec 20 12:46:11 2024 -0800
Add gstack script
And adds -h | --help options to the gcore script, and smartens up the
help and usage output messages.
The usage text is now split over several lines (as it was getting a
bit long), and an input error suggests using `--help` instead of
printing the full usage string.
These changes bring gcore and gstack closer in behaviour.
---
gdb/NEWS | 3 ++-
gdb/doc/gdb.texinfo | 6 +++++-
gdb/gcore-1.in | 50 ++++++++++++++++++++++++++++++++++++++++-----
3 files changed, 52 insertions(+), 7 deletions(-)
diff --git a/gdb/NEWS b/gdb/NEWS
index d4453914755..5d9d9fb3063 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -27,7 +27,8 @@
* Linux checkpoint code has been updated to work with multiple inferiors.
* The gcore script now has a -v or --version option, which prints the
- version number, and then exits.
+ version number, and then exits. As well as a -h or --help option,
+ which prints each options and a brief description.
* New commands
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 1ab87dd37f9..a1ae45c5121 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -51386,7 +51386,7 @@ gcore man
@format
@c man begin SYNOPSIS gcore
-gcore [-v | --version] [-a] [-o @var{prefix}] [-d @var{directory}]
+gcore [-v | --version] [-h | --help] [-a] [-o @var{prefix}] [-d @var{directory}]
@var{pid1} [@var{pid2}...@var{pidN}]
@c man end
@end format
@@ -51420,6 +51420,10 @@ gcore man
Use @var{directory} as the data directory when invoking @value{GDBN} for running
the gcore command. This argument is optional.
+@item --help
+@itemx -h
+List all options, with brief explanations.
+
@item --version
@itemx -v
Print version information and then exit.
diff --git a/gdb/gcore-1.in b/gdb/gcore-1.in
index ce2f7321148..129e3697fb7 100644
--- a/gdb/gcore-1.in
+++ b/gdb/gcore-1.in
@@ -32,11 +32,38 @@ dump_all_cmds=()
data_directory_opt=()
+function print_usage() {
+ prefix="Usage: $0"
+ paddin=$(printf '%*s' ${#prefix})
+
+ echo "$prefix [-h|--help] [-v|--version]"
+ echo "$paddin [-a] [-o prefix] [-d data-directory]"
+ echo "$paddin pid1 [pid2...pidN]"
+}
+
+function print_try_help() {
+ echo "Try '$0 --help' for more information."
+}
+
+function print_help() {
+ print_usage
+ echo
+ echo "Create a core file of a running program using GDB."
+ echo
+ echo " -h, --help Print this message then exit."
+ echo " -v, --version Print version information then exit."
+ echo " -a Dump all memory mappings."
+ echo " -o prefix Use 'prefix.pid' as the core file name."
+ echo " The default prefix is 'core'."
+ echo " -d dir Pass '--data-directory dir' as an argument"
+ echo " to GDB."
+}
+
function print_version() {
echo "GNU gcore (${PKGVERSION}) ${VERSION}"
}
-while getopts :vao:d:-: OPT; do
+while getopts vhao:d:-: OPT; do
if [ "$OPT" = "-" ]; then
OPT="${OPTARG%%=*}"
OPTARG="${OPTARG#'$OPT'}"
@@ -58,13 +85,26 @@ while getopts :vao:d:-: OPT; do
d)
data_directory_opt=("--data-directory" "$OPTARG")
;;
+ h | help)
+ print_help
+ exit 0
+ ;;
v | version)
print_version
exit 0
;;
+ \?)
+ # getopts has already output an error message.
+ print_try_help 1>&2
+ exit 2
+ ;;
*)
- echo "usage: @GCORE_TRANSFORM_NAME@ [-v | --version] [-a] [-o prefix] [-d data-directory] pid1 [pid2...pidN]"
- exit 2
+ # Unknown single character options are handled by the \?
+ # case above. This is formatted to match the error
+ # getopts gives for an unknown single character option.
+ echo "$0: illegal option -- $OPT" 1>&2
+ print_try_help 1>&2
+ exit 2
;;
esac
done
@@ -73,8 +113,8 @@ shift $((OPTIND-1))
if [ "$#" -eq "0" ]
then
- echo "usage: @GCORE_TRANSFORM_NAME@ [-a] [-o prefix] [-d data-directory] pid1 [pid2...pidN]"
- exit 2
+ print_usage 1>&2
+ exit 1
fi
# Attempt to fetch the absolute path to the gcore script that was
--
2.47.1
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 2/3] gcore: add -h|--help options, and improve help/usage message output
2025-03-06 17:10 ` [PATCH 2/3] gcore: add -h|--help options, and improve help/usage message output Andrew Burgess
@ 2025-03-06 17:33 ` Eli Zaretskii
0 siblings, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2025-03-06 17:33 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches
> From: Andrew Burgess <aburgess@redhat.com>
> Cc: Andrew Burgess <aburgess@redhat.com>
> Date: Thu, 6 Mar 2025 17:10:23 +0000
>
> Like the previous commit, this copies a lot from:
>
> commit fb2ded33c1e519659743047ed7817166545b6d91
> Date: Fri Dec 20 12:46:11 2024 -0800
>
> Add gstack script
>
> And adds -h | --help options to the gcore script, and smartens up the
> help and usage output messages.
>
> The usage text is now split over several lines (as it was getting a
> bit long), and an input error suggests using `--help` instead of
> printing the full usage string.
>
> These changes bring gcore and gstack closer in behaviour.
> ---
> gdb/NEWS | 3 ++-
> gdb/doc/gdb.texinfo | 6 +++++-
> gdb/gcore-1.in | 50 ++++++++++++++++++++++++++++++++++++++++-----
> 3 files changed, 52 insertions(+), 7 deletions(-)
OK for the documentation parts, thanks.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 3/3] gcore/doc: fix mistake in the gcore man page
2025-03-06 17:10 [PATCH 0/3] gcore: add --help and --version options Andrew Burgess
2025-03-06 17:10 ` [PATCH 1/3] gcore: add -v or --version option to show version number Andrew Burgess
2025-03-06 17:10 ` [PATCH 2/3] gcore: add -h|--help options, and improve help/usage message output Andrew Burgess
@ 2025-03-06 17:10 ` Andrew Burgess
2025-03-06 17:32 ` Eli Zaretskii
2025-03-06 20:16 ` [PATCH 0/3] gcore: add --help and --version options Tom Tromey
2025-03-06 20:19 ` Tom Tromey
4 siblings, 1 reply; 9+ messages in thread
From: Andrew Burgess @ 2025-03-06 17:10 UTC (permalink / raw)
To: gdb-patches; +Cc: Andrew Burgess
The gcore man page says that the default prefix for a generated core
file will be 'gcore', i.e. we'll create files like 'gcore.pid'. In
reality the default is 'core'.
As far as I can tell, the default has been 'core' for years, and the
docs used to say that the default was 'core', but the docs were
changed by mistake in commit:
commit 129eb0f1f16dc7a49799a024a7bcb109d954a1e7
Date: Fri Jul 27 00:52:23 2018 -0400
Improve gcore manpage and clarify "-o" option
So, lets bring the docs back inline with the code.
---
gdb/doc/gdb.texinfo | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index a1ae45c5121..5a8f8bddc05 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -51414,7 +51414,7 @@ gcore man
when composing the file names of the core dumps. The file name is
composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
process ID of the running program being analyzed by @command{gcore}.
-If not specified, @var{prefix} defaults to @var{gcore}.
+If not specified, @var{prefix} defaults to @var{core}.
@item -d @var{directory}
Use @var{directory} as the data directory when invoking @value{GDBN} for running
--
2.47.1
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 3/3] gcore/doc: fix mistake in the gcore man page
2025-03-06 17:10 ` [PATCH 3/3] gcore/doc: fix mistake in the gcore man page Andrew Burgess
@ 2025-03-06 17:32 ` Eli Zaretskii
0 siblings, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2025-03-06 17:32 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches
> From: Andrew Burgess <aburgess@redhat.com>
> Cc: Andrew Burgess <aburgess@redhat.com>
> Date: Thu, 6 Mar 2025 17:10:24 +0000
>
> The gcore man page says that the default prefix for a generated core
> file will be 'gcore', i.e. we'll create files like 'gcore.pid'. In
> reality the default is 'core'.
>
> As far as I can tell, the default has been 'core' for years, and the
> docs used to say that the default was 'core', but the docs were
> changed by mistake in commit:
>
> commit 129eb0f1f16dc7a49799a024a7bcb109d954a1e7
> Date: Fri Jul 27 00:52:23 2018 -0400
>
> Improve gcore manpage and clarify "-o" option
>
> So, lets bring the docs back inline with the code.
> ---
> gdb/doc/gdb.texinfo | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
This is okay, thanks.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/3] gcore: add --help and --version options
2025-03-06 17:10 [PATCH 0/3] gcore: add --help and --version options Andrew Burgess
` (2 preceding siblings ...)
2025-03-06 17:10 ` [PATCH 3/3] gcore/doc: fix mistake in the gcore man page Andrew Burgess
@ 2025-03-06 20:16 ` Tom Tromey
2025-03-06 20:19 ` Tom Tromey
4 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2025-03-06 20:16 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches
>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
Andrew> The new gstack script has --help and --version options, which is more
Andrew> than the older gcore script has!
Andrew> This series adds these options to gcore, and also fixes a minor doc
Andrew> typo relating to gcore.
This was mentioned in
https://sourceware.org/bugzilla/show_bug.cgi?id=32325 so maybe that
link should appear in one of the patches.
Tom
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 0/3] gcore: add --help and --version options
2025-03-06 17:10 [PATCH 0/3] gcore: add --help and --version options Andrew Burgess
` (3 preceding siblings ...)
2025-03-06 20:16 ` [PATCH 0/3] gcore: add --help and --version options Tom Tromey
@ 2025-03-06 20:19 ` Tom Tromey
4 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2025-03-06 20:19 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches
>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
Andrew> The new gstack script has --help and --version options, which is more
Andrew> than the older gcore script has!
Andrew> This series adds these options to gcore, and also fixes a minor doc
Andrew> typo relating to gcore.
I read through these & they all look good to me.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 9+ messages in thread