You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GDB自定义命令中loop_continue触发警告问题求助

GDB自定义命令中loop_continue触发警告的问题

为练习loop_continue,我编写了如下GDB自定义命令:

#
# Print all odd numbers less than a given number.
#
define print_all_odds_less_than
    set $max = $arg0
    set $i   = 0

    while $i < ($max - 1)
        set $i = $i + 1

        if ($i % 2) == 0
            loop_continue
        end

        printf "Odd number %u is less than %u\n", $i, $max
    end

    printf "Done\n"
end

正常运行示例:

(gdb) print_all_odds_less_than 10
Odd number 1 is less than 10
Odd number 3 is less than 10
Odd number 5 is less than 10
Odd number 7 is less than 10
Odd number 9 is less than 10
Done

但当输入某个值(比如9),导致最后一次执行loop_continue后while循环不再运行时,会触发警告且自定义命令中止执行:

(gdb) print_all_odds_less_than 9
Odd number 1 is less than 9
Odd number 3 is less than 9
Odd number 5 is less than 9
Odd number 7 is less than 9
warning: Error executing canned sequence of commands.

loop_continue的官方文档说明:

This command skips the execution of the rest of the body of commands
in the while loop in whose body it is included. Execution branches to
the beginning of the while loop, where it evaluates the controlling
expression.

我查阅上述文档后仍无法理解代码中的错误。我的GDB版本:

bash$ gdb --version
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1

恳请提供帮助 :)


内容的提问来源于stack exchange,提问作者Anant

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 02:25:47