From: Simon Marchi <simark@simark.ca>
To: Guinevere Larsen <guinevere@redhat.com>, Eli Zaretskii <eliz@gnu.org>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb: add tutorial command
Date: Wed, 3 Dec 2025 12:27:19 -0500 [thread overview]
Message-ID: <4528decb-897a-4d22-a27e-8ad67d13df58@simark.ca> (raw)
In-Reply-To: <b8f85690-64c1-4ead-9315-861199389119@redhat.com>
On 2025-12-03 08:07, Guinevere Larsen wrote:
>> 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.)
I agree that it's perhaps not necessary to have a program with a bug,
and explain what is the bug, etc. It seems distracting to me. Having a
program that does something simple (without being too trivial) would be
sufficient to teach the user how to launch, navigate and print values.
I have minor comments like this on the content of the tutorial but
haven't had the time to formulate them. I thought we would resolve the
more major issues / disagreements first.
>> 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.
For this tutorial and the way it works (the user doing actions makes
the tutorial progress forward), I think we need something extremely
predictable. Using the GDB production binary is never going to work for
that, on top of the other issues (like obtaining debug info).
>> 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.
It seems like there is a disagreement on the target audience for this
tutorial (which we could imagine being chapter 1 of a more comprehensive
tutorial). Eli seems to think it should target seasoned programmers who
write complex programs. Guinevere seems to think that it should be
accessible to people who start programming.
And I also think that it should be accessible to beginners, showing them
early in their journey that debuggers are useful. Even if the example
is a toy one, I think that experienced programmers will be able to
extrapolate it to their own programs. We can discuss further how the
material is presented exactly, but I think that the core of commands
presented in this tutorial already goes a long way, even when debugging
complex programs.
> 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.
I agree, 95% of my day to day GDB usage to debug GDB must be:
- break
- run
- print variable
- step, step, next, finish
- print variable
- exit
It's not to say that other commands aren't useful on occasion, but for
the scope of a 10 minutes (or whatever is the maximum attention span
nowadays) tutorial, I think it's fine.
>> 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.
Off the top of my head, I think that conditional breakpoints should be
explained. They are relatively simple to use and useful in real-world
situations. But this introduction tutorial would not be the right
place, perhaps in an eventual subsequent chapter.
>> 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.
I don't really see it as showing debugging techniques. The tutorial
with the toy example allows users to try the GDB command being taught
for themselves and see the result. Which I guess is the point of an
interactive tutorial, over just a list of "command X does that".
Simon
prev parent reply other threads:[~2025-12-03 17:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-01 17:08 Guinevere Larsen
2025-12-02 14:20 ` Eli Zaretskii
2025-12-02 17:02 ` Guinevere Larsen
2025-12-02 19:33 ` Simon Marchi
2025-12-03 12:43 ` Eli Zaretskii
2025-12-03 13:07 ` Guinevere Larsen
2025-12-03 17:27 ` Simon Marchi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4528decb-897a-4d22-a27e-8ad67d13df58@simark.ca \
--to=simark@simark.ca \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=guinevere@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox