Re: behavior of 'step' command in scripts execution

Simon Marchi <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>
On 14-01-25 09:14 PM, dgutson . wrote:
> Why a step command stops the execution of a breakpoint's commands?
> 
> For example, consider these files:
> 
> //file.cpp:
> #include <iostream>
> using namespace std;
> 
> int f(int x)
> {
>     x++;          // this is line 6
>     return x;
> }
> 
> int main()
> {
>     cout << f(3);
> }
> 
> // file.gdb
> br file.cpp:6
> comm
> silent
> step
> set x=5
> cont
> end
> 
> When I run gdb with the binary and the script, execution stops in the
> "return x" line (line 7), getting gdb's prompt and x is not modified.
> If I enter "continue", "4" is shown.
> I observe this behavior since many versions ago (don't recall since
> when, and I don't know if it has ever been in another way). I compiled
> the example with -ggdb3 option.
> 
> What I would expect is that the breakpoint's commands execute all, and
> get "5" as output.
> 
> If there is agreement, I'd like to write a patch to fix this behavior
> through a setting, something like
>     set set-behavior continue
> or alike, so it won't break compatibility.
> 
> Thanks,
>    Daniel.

Hi Daniel,

From the GDB manual:

> You can use breakpoint commands to start your program up again. Simply use
> the continue command, or step, or any other command that resumes execution.

> Any other commands in the command list, after a command that resumes
> execution, are ignored. This is because any time you resume execution (even
> with a simple next or step), you may encounter another breakpoint—which
> could have its own command list, leading to ambiguities about which list to
> execute.

I think that sums it up pretty well. If you want to make a mode where this is allowed, you should think carefully how those ambiguities will be handled.

Simon

Source: https://sourceware.org/gdb/onlinedocs/gdb/Break-Commands.html#Break-Commands
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.