On 12/3/25 9:43 AM, Eli Zaretskii wrote:
Date: Tue, 2 Dec 2025 14:33:08 -0500
Cc: gdb-patches@sourceware.org
From: Simon Marchi <simark@simark.ca>

First, writing this command in Python means that GDB without Python
will not have a tutorial, which is IMO a pity.  Is it so complicated
to have this implemented in C++ instead?  The text and the basic
script of the tutorial session could be on a text file that code
accesses when the tutorial is running, so that only the necessary
stuff needs to be in code.
If possible, it would indeed be nice, but I'll take a tutorial written
in Python over nothing.
If the C++ implementation is not feasible or not practical, I agree.
My point is that we should consider that possibility before deciding
on a Python implementation.

Next, I'm not sure we need to compile a program for this purpose.  We
could use the GDB executable itself instead: that would allow us to
show the basic commands without the need for the user to have a
compiler and a working development environment to go with it.
I don't see how that's feasible or practical.  The GDB binary users are
most likely to have are optimized (bad debugging experience, especially
if you're learning) and won't have debug info anyway.  And like
Guinevere said, GDB is way too complicated to throw at newbies anyway.
I like Guinevere's idea of giving the user a small program they can toy
with.
This is a _GDB_ tutorial.  It doesn't need to include a complete
debugging problem described in its entirety, right up to finding the
bug and fixing it.  It needs to show the use of important GDB
commands, under the assumption that the person using the tutorial
knows how to debug programs, but is not familiar with GDB commands to
do that.  (Yes, teaching debugging techniques in addition is helpful,
but IMO the minimal requirements from a useful tutorial are to teach
the commands.)

For the purpose of teaching the useful commands, it doesn't matter
much that GDB is optimized, the only possible problem could be that
it's stripped.  If it is not stripped, I don't see why we couldn't
show use of important commands on GDB itself, explaining their purpose
in plain text.  There's no need to solve an actual bug, just let users
tinker with commands when they have a live program at their disposal.
Whatever the complexity of GDB, users definitely can step it, step
into functions, examine its data, set breakpoints and watchpoints and
see them break, etc.  We could also show how to change values of
variables and call functions from the program.  

It does matter that GDB is optimized, though. Assuming that the user could get debug info, they could use "next" and end up in a previous line because the compiler decided to reorder instructions/lines, they could try to step into a function that was entirely optimized away, they could try to read the value of a variable only to find that it was optimized away

And, most importantly, if they aren't familiar with GDB, it isn't unreasnable to think they never used a debugger before and only did printf debugging. Having those confusing reactions would only cement in such user's brains that debuggers are actually not as useful as printf, because variables can disappear when they never do in a printf, for example.

Lastly, we aren't arguing about still needing to come up with a small toy problem. I already did that, the code is already here. The decision is "should we scrap what has already been done or not" rather than "should we come up with something very good from scratch or not".

Moreover, if we limit
ourselves to teaching commands, we can show advanced commands and
techniques, like working with threads and scheduling them, following
'fork', handling signals, etc. -- these are hard to impossible to do
with toy programs, but they are needed in most real-life debugging
sessions.

These are most definitely out of scope for a tutorial that opens with "welcome to GDB" and assumes minimal knowledge of programming in general. But that's ok, because this doesn't have to be the only tutorial. What I'm presenting here is a quickstart tutorial, that'll get users acquainted with general purpose tools, and this framework can easily be expanded to have specific tutorials, like multi-threaded debugging, reverse debugging, linker namespace debugging and other advanced cases I haven't ran into.

Also, I think it's worth to note that I haven't used any of the other commands. So unless my last 5 years of work experience (4 of them in GDB) aren't real life debugging sessions, I think you're overestimating the commonality of the issues you deal with.


Also, a tutorial doesn't have to teach people how to debug, it could
only teach them the important GDB commands to use for debugging.
Doing both makes the tutorial more complex because it teaches two
non-trivial subjects instead of just one.

What do others think?
I don't understand your last point.  Do you mean that the tutorial
should just be some text that says "you can use command X to do this,
command Y to do that, etc"?  Seems way less interesting and interactive
than what is proposed here.
Yes, I mean just describe the important commands and let the user try
them and see the results.
Then I don't see the difference between using "tutorial" or telling the user to use "help essential". And if that is your suggestion, we already have the C++ implementation of a tutorial.

Indeed, teaching both debugging techniques and GDB commands is better,
but that job is much more complex if taken seriously.  
But I already did the job. This is already implemented. Your suggestion is that, because the task is hard, we shouldn't use the solution I already came up with?
And I question
the actual value of showing how to debug a toy program anyway, because
it is nothing like debugging real-life programs.  
I am unfamiliar with any starter tutorial that, both, starts with a real life example showing all the complexities of real life example and is well liked at the same time.
The latter
frequently requires advanced techniques, some of them special to the
program in question (e.g., see etc/DEBUG in the Emacs source tree).

Again, this isn't meant to be the tutorial that teaches all of GDB; to quote the tutorial's own opening words: "This quick tutorial should be enough to get ou acquainted with essential commands for basic debugging."

Once a first tutorial goes through and we have a basic framework for how to teach things to users, you're welcome to try your hand at teaching the advanced techniques with a tutorial of your own, say "tutorial multithreaded" for example.

So I suggest to start from a modest task of showing and teaching the
important commands, leaving the rest to the users, who will need to
learn much more, if they never debugged a real-life program.  We may
decide in the future to have a separate tutorial about debugging
techniques.

Please note that the above is just MO; I will not object and won't
argue if you-all think differently.  I just wanted to present an
alternative POV, so that people could think about this and make up
their minds.  After all, it is unlikely that I will use this tutorial
myself...


-- 
Cheers,
Guinevere Larsen
It/she