Skip to content

Commit f8b3ba9

Browse files
committed
Go over documentation...
Add a more expansive explicit debugger call example.
1 parent 206b2b5 commit f8b3ba9

File tree

5 files changed

+114
-21
lines changed

5 files changed

+114
-21
lines changed

doc/bashdb.texi

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ This is the @value{EDITION} Edition, @value{UPDATED},
6868
of @cite{Debugging with BASHDB: the @sc{gnu} Source-Level Debugger}
6969
for BASH
7070

71-
Copyright (C) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2011
71+
Copyright (C) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2011, 2024
7272
Rocky Bernstein for the Free Software Foundation.
7373

7474
Permission is granted to copy, distribute and/or modify this document
@@ -838,6 +838,76 @@ script.
838838
Options for the @emph{bashdb} front-end are shown in the
839839
following list.
840840

841+
@node Calling the debugger from inside a running bash script
842+
@subsection Calling the debugger from inside a shell script
843+
844+
Running bash scripts when the debugger has been started can slow down
845+
your program. In most programs this is not a big problem. However, in
846+
large bash script this slowdown can be very noticable. Autogenerated
847+
@code{configure} script fall in to this category.
848+
849+
Instead of invoking @code{bashdb} from the outset, or have having
850+
@code{bash} the same, you can instead modify your program to make a
851+
call to the debugger at a point inside your program.
852+
853+
This way, your code runs full speed, and the debugger is not even
854+
present, until the point where you wan to start debuggingere.
855+
856+
Here is how you do this. Consider this script adapted from @code{/etc/profile}
857+
on Ubuntu GNU/Linux systems:
858+
859+
@smallexample
860+
@cartouche
861+
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
862+
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
863+
864+
if [ "$PS1" ]; then
865+
# 15 lines omitted
866+
fi
867+
868+
if [ -d /etc/profile.d ]; then
869+
for i in /etc/profile.d/*.sh; do
870+
if [ -r $i ]; then
871+
if [[ $i == "/etc/profile.d/bash_completion.sh"; then
872+
# Load in debugger
873+
. /usr/share/bashdb/bashdb-trace -q
874+
# Call debugger
875+
_Dbg_debugger
876+
fi
877+
. $i
878+
fi
879+
done
880+
unset i
881+
fi
882+
@end cartouche
883+
@end smallexample
884+
885+
The lines:
886+
887+
@smallexample
888+
@cartouche
889+
# Load in debugger
890+
. /usr/share/bashdb/bashdb-trace -q
891+
# Call debugger
892+
_Dbg_debugger
893+
. $i
894+
@end cartouche
895+
@end smallexample
896+
897+
Have been added. The line @code{. /usr/share/bashdb/bashdb-trace -q}
898+
pulls in the debugger code using bash's ``source'' command. After
899+
that, an explicit call to the debbugger is made. Here, it is done to
900+
be able to debug the bash completion code in
901+
@code{/etc/profile.d/bash_completion.sh} if that exists in the
902+
filesystem.
903+
904+
The file name @code{/usr/share/bashdb/bashdb-trace} may need to be
905+
adjusted based on the location @code{bashdb} was installed. Here, it
906+
was installed in @code{/usr/share/bashdb}.
907+
908+
Again, there is no overhead or knowledge of the debugger before the
909+
source command.
910+
841911
@menu
842912
* Options for the bashdb script:: Options you can pass in starting bashdb
843913
@end menu

docs/commands/running/continue.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.. _continue:
33

44
Continue Program Execution (``continue``)
5-
---------------------------------------
5+
------------------------------------------
66

77
**continue** [ *loc* | **-*** ]
88

docs/commands/set/different.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.. _set_different:
33

44
Consecutive Stops on Different File/Line Positions) (``set different``)
5-
---------------------------------------------------------------------
5+
-----------------------------------------------------------------------
66

77
**set different** [ **on** | **off** ]
88

docs/entry-exit.rst

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Entering the Bash Debugger
2-
****************************
2+
**************************
33

44
.. toctree::
55
.. contents::
66

77

88
Invoking the Debugger Initially
9-
====================================
9+
===============================
1010

1111
The simplest way to debug your program is to run ``bashdb``. Give
1212
the name of your program and its options and any debugger options:
@@ -52,35 +52,58 @@ For help on `bashdb` or options, use the ``--help`` option.
5252
5353
5454
Calling the debugger from your program
55-
===========================================
55+
======================================
56+
57+
Sometimes it is not possible to invoke the program you want debugged
58+
from the ``bashdb`` or from ``bash --debugger``.
5659

57-
Sometimes it is not feasible to invoke the program from the debugger.
5860
Although the debugger tries to set things up to make it look like your
59-
program is called, sometimes the differences matter. Also the debugger
60-
adds overhead and slows down your program.
61+
program is called, sometimes the differences matter. Also, once the debugger
62+
is loaded this can slows in parts that you do not want to debug.
6163

62-
Another possibility then is to add statements into your program to call
63-
the debugger at the spot in the program you want. To do this, you source
64-
``bashdb/dbg-trace.sh`` from where wherever it appears on your filesystem.
65-
This needs to be done only once.
64+
So instead, you can add statements into your program to call the
65+
debugger at the spot in the program you want. To do this, you source
66+
``bashdb/dbg-trace.sh`` from where wherever it appears on your
67+
filesystem. This needs to be done only once.
6668

6769
After that you call ``_Dbg_debugger``.
6870

69-
Here is an Example:
71+
Consider the example of the previous section, but you to debug
72+
``/etc/profile.d/bash_completion.sh`` and skip over the other default
73+
profile scripts at high speed. Here is how you might do this:
7074

7175
.. code:: console
7276
73-
source path-to-bashdb/bashdb/dbg-trace.sh
74-
# work, work, work.
75-
# ... some bash code
77+
if [ "${PS1-}" ]; then
78+
# 15 lines omitted
79+
fi
7680
77-
_Dbg_debugger
78-
# start debugging here
81+
if [ -d /etc/profile.d ]; then
82+
for i in /etc/profile.d/*.sh; do
83+
if [ -r $i ]; then
84+
if [[ $i == "/etc/profile.d/bash_completion.sh"; then
85+
# Load in debugger
86+
. /usr/share/bashdb/bashdb-trace -q
87+
# Call debugger
88+
_Dbg_debugger
89+
fi
90+
. $i
91+
fi
92+
done
93+
unset i
94+
fi
7995
8096
81-
Since `_Dbg_debugger`` a function call, it can be nested inside some sort of
97+
Since ``_Dbg_debugger`` is a function call, it can be nested inside some sort of
8298
conditional statement allowing one to be very precise about the
8399
conditions you want to debug under. And until first call to ``_Dbg_debugger``,
84100
there is no debugger overhead.
85101

86102
Note that ``_Dbg_debugger`` causes the statement *after* the call to be stopped at.
103+
104+
The file name ``/usr/share/bashdb/bashdb-trace`` may need to be
105+
adjusted based on the location ``bashdb`` was installed. Here, on
106+
my Ubuntu GNU/Linux system it was installed in ``/usr/share/bashdb``.
107+
108+
Again, there is no overhead or knowledge of the debugger before the
109+
first source command to ``bashdb-trace``.

docs/manpage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.. contents::
55

66
bashdb command
7-
#############
7+
##############
88

99
Synopsis
1010
--------

0 commit comments

Comments
 (0)