diff options
author | Keith Seitz <keiths@redhat.com> | 2024-12-20 12:46:11 -0800 |
---|---|---|
committer | Keith Seitz <keiths@redhat.com> | 2024-12-20 12:46:11 -0800 |
commit | fb2ded33c1e519659743047ed7817166545b6d91 (patch) | |
tree | 82e18cd2ab819e76f52822e571ec2d4872261718 /gdb/doc | |
parent | db7e13a9a2f2b60bf13c22fde9ab5d24ef8df88e (diff) | |
download | binutils-fb2ded33c1e519659743047ed7817166545b6d91.zip binutils-fb2ded33c1e519659743047ed7817166545b6d91.tar.gz binutils-fb2ded33c1e519659743047ed7817166545b6d91.tar.bz2 |
Add gstack script
This commit adds support for a `gstack' command which Fedora has
been carrying for many years. gstack is a natural counterpart to
the gcore command. Whereas gcore dumps a core file, gstack prints
stack traces of a running process.
There are many improvements over Fedora's version of this script.
The dependency on procfs is gone; gstack will run anywhere gdb
runs. The only runtime dependencies are bash and awk.
The script includes suggestions from gdb/32325 to include
versioning and help. [If this approach to gdb/32325 is acceptable,
I could propagate the solution to gcore/gdb-add-index.]
I've rewritten the documentation, integrating it into the User Manual.
The manpage is now output using this one source.
Example run (on x86_64 Fedora 40)
$ gstack --help
Usage: gstack [-h|--help] [-v|--version] PID
Print a stack trace of a running program
-h, --help Print this message then exit.
-v, --version Print version information then exit.
$ gstack -v
GNU gstack (GDB) 16.0.50.20241119-git
$ gstack 12345678
Process 12345678 not found.
$ gstack $(pidof emacs)
Thread 6 (Thread 0x7fd5ec1c06c0 (LWP 2491423) "pool-spawner"):
#0 0x00007fd6015ca3dd in syscall () at /lib64/libc.so.6
#1 0x00007fd60b31eccd in g_cond_wait () at /lib64/libglib-2.0.so.0
#2 0x00007fd60b28a61b in g_async_queue_pop_intern_unlocked () at /lib64/libglib-2.0.so.0
#3 0x00007fd60b2f1a03 in g_thread_pool_spawn_thread () at /lib64/libglib-2.0.so.0
#4 0x00007fd60b2f0813 in g_thread_proxy () at /lib64/libglib-2.0.so.0
#5 0x00007fd6015486d7 in start_thread () at /lib64/libc.so.6
#6 0x00007fd6015cc60c in clone3 () at /lib64/libc.so.6
#7 0x0000000000000000 in ??? ()
Thread 5 (Thread 0x7fd5eb9bf6c0 (LWP 2491424) "gmain"):
#0 0x00007fd6015be87d in poll () at /lib64/libc.so.6
#1 0x0000000000000001 in ??? ()
#2 0xffffffff00000001 in ??? ()
#3 0x0000000000000001 in ??? ()
#4 0x000000002104cfd0 in ??? ()
#5 0x00007fd5eb9be320 in ??? ()
#6 0x00007fd60b321c34 in g_main_context_iterate_unlocked.isra () at /lib64/libglib-2.0.so.0
Thread 4 (Thread 0x7fd5eb1be6c0 (LWP 2491425) "gdbus"):
#0 0x00007fd6015be87d in poll () at /lib64/libc.so.6
#1 0x0000000020f9b558 in ??? ()
#2 0xffffffff00000003 in ??? ()
#3 0x0000000000000003 in ??? ()
#4 0x00007fd5d8000b90 in ??? ()
#5 0x00007fd5eb1bd320 in ??? ()
#6 0x00007fd60b321c34 in g_main_context_iterate_unlocked.isra () at /lib64/libglib-2.0.so.0
Thread 3 (Thread 0x7fd5ea9bd6c0 (LWP 2491426) "emacs"):
#0 0x00007fd6015ca3dd in syscall () at /lib64/libc.so.6
#1 0x00007fd60b31eccd in g_cond_wait () at /lib64/libglib-2.0.so.0
#2 0x00007fd60b28a61b in g_async_queue_pop_intern_unlocked () at /lib64/libglib-2.0.so.0
#3 0x00007fd60b28a67c in g_async_queue_pop () at /lib64/libglib-2.0.so.0
#4 0x00007fd603f4d0d9 in fc_thread_func () at /lib64/libpangoft2-1.0.so.0
#5 0x00007fd60b2f0813 in g_thread_proxy () at /lib64/libglib-2.0.so.0
#6 0x00007fd6015486d7 in start_thread () at /lib64/libc.so.6
#7 0x00007fd6015cc60c in clone3 () at /lib64/libc.so.6
#8 0x0000000000000000 in ??? ()
Thread 2 (Thread 0x7fd5e9e6d6c0 (LWP 2491427) "dconf worker"):
#0 0x00007fd6015be87d in poll () at /lib64/libc.so.6
#1 0x0000000000000001 in ??? ()
#2 0xffffffff00000001 in ??? ()
#3 0x0000000000000001 in ??? ()
#4 0x00007fd5cc000b90 in ??? ()
#5 0x00007fd5e9e6c320 in ??? ()
#6 0x00007fd60b321c34 in g_main_context_iterate_unlocked.isra () at /lib64/libglib-2.0.so.0
Thread 1 (Thread 0x7fd5fcc45280 (LWP 2491417) "emacs"):
#0 0x00007fd6015c9197 in pselect () at /lib64/libc.so.6
#1 0x0000000000000000 in ??? ()
Since this is essentially a complete rewrite of the original
script and documentation, I've chosen to only keep a 2024 copyright date.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/doc')
-rw-r--r-- | gdb/doc/Makefile.in | 11 | ||||
-rw-r--r-- | gdb/doc/gdb.texinfo | 70 |
2 files changed, 80 insertions, 1 deletions
diff --git a/gdb/doc/Makefile.in b/gdb/doc/Makefile.in index 181325f..c75714b 100644 --- a/gdb/doc/Makefile.in +++ b/gdb/doc/Makefile.in @@ -188,7 +188,7 @@ TEXI2POD = perl $(srcdir)/../../etc/texi2pod.pl \ POD2MAN = pod2man --center="GNU Development Tools" # List of man pages generated from gdb.texi -MAN1S = gdb.1 gdbserver.1 gcore.1 gdb-add-index.1 +MAN1S = gdb.1 gdbserver.1 gcore.1 gstack.1 gdb-add-index.1 MAN5S = gdbinit.5 MANS = $(MAN1S) $(MAN5S) @@ -199,6 +199,7 @@ POD_FILE_TMPS = $(patsubst %.1,%.pod,$(MAN1S)) \ HAVE_NATIVE_GCORE_TARGET = @HAVE_NATIVE_GCORE_TARGET@ HAVE_NATIVE_GCORE_HOST = @HAVE_NATIVE_GCORE_HOST@ +HAVE_GSTACK = @HAVE_GSTACK@ ### @@ -339,6 +340,10 @@ install-man1: $(MAN1S) -a "$$p" = gcore.1; then \ continue; \ fi; \ + if test "x$(HAVE_GSTACK)" = x \ + -a "$$p" = gstack.1; then \ + continue; \ + fi; \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ f=`echo $$p | sed -e 's|^.*/||' -e '$(transform)'`; \ echo " $(INSTALL_DATA) '$$d$$p' '$(DESTDIR)$(man1dir)/$$f'"; \ @@ -363,6 +368,10 @@ uninstall-man1: -a "$$i" = gcore.1; then \ continue; \ fi; \ + if test "x$(HAVE_GSTACK)" = x \ + -a "$$i" = gstack.1; then \ + continue; \ + fi; \ echo "$$i"; \ done | \ sed -n '/\.1[a-z]*$$/p'; \ diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 7b6000a..b985399 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -50584,6 +50584,7 @@ Show the current verbosity setting. * gdb man:: The GNU Debugger man page * gdbserver man:: Remote Server for the GNU Debugger man page * gcore man:: Generate a core file of a running program +* gstack man:: Print a stack trace of a running program * gdbinit man:: gdbinit scripts * gdb-add-index man:: Add index files to speed up GDB @end menu @@ -51266,6 +51267,75 @@ Richard M. Stallman and Roland H. Pesch, July 1991. @end ifset @c man end +@node gstack man +@heading gstack + +@c man title gstack Print a stack trace of a running program + +@format +@c man begin SYNOPSIS gstack +gstack [-h | --help] [-v | --version] @var{pid} +@c man end +@end format + +@c man begin DESCRIPTION gstack +Print a stack trace of a running program with process ID @var{pid}. If the process +is multi-threaded, @command{gstack} outputs backtraces for every thread which exists +in the process. + +The script invokes @value{GDBN}, attaches to the given process ID, prints the stack trace, +and detaches from the process. + +@command{gstack} exits with non-zero status if @code{gdb} was unable to attach to +the given process ID for any reason, such as a non-existent process ID or +insufficient privileges to attach to the process. +@c man end + +@c man begin OPTIONS gstack +@table @env +@item --help +@itemx -h +List all options, with brief explanations. + +@item --version +@itemx -v +Print version information and then exit. +@end table +@c man end + +@c man begin ENVIRONMENT gstack +@table @env +@item AWK +Full file name for an Awk interpreter to use. If not set, @env{PATH} will be +searched for an @code{awk} program. + +@item GDB +Full file name for a @value{GDBN} executable to use to generate stack backtraces. +If not set, @env{PATH} will be searched for a @code{gdb} program. + +@item GDBARGS +Optional arguments to be passed to the @code{gdb} program. +@end table +@c man end + +@c man begin SEEALSO gstack +@ifset man +The full documentation for @value{GDBN} is maintained as a Texinfo manual. +If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo +documentation are properly installed at your site, the command + +@smallexample +info gdb +@end smallexample + +@noindent +should give you access to the complete manual. + +@cite{Using GDB: A Guide to the GNU Source-Level Debugger}, +Richard M. Stallman and Roland H. Pesch, July 1991. +@end ifset +@c man end + @node gdbinit man @heading gdbinit |