2

我有一个 gdb 用户定义的命令,它会做一些设置,然后可能会做一个简单的工作,或者一个复杂的工作。该命令遵循以下基本结构:

define mycmd
  # Common setup

  if ($argc == 0)
    # Some simple thing a few lines long
    ## What goes here so I exit mycmd?
  end

  # A lot of lines doing a complex thing
end

是否可以使用类似 C 的返回来代替 ## 行以立即终止 mycmd?return、exit、quit、stop、loop_break 命令没有达到我的预期。

4

2 回答 2

2

是否有类似 C 的返回

似乎没有。一个可能的解决方案是

define mycmd
   ... common setup
   if (condition)
     ... do simple thing
   else
     mycmd_helper
   end
end

define mycmd_helper
   ... do complex thing
end
于 2012-09-27T13:59:18.367 回答
1

这不是它的主要用途,但您可以使用 loop_break:

define mycmd
  # Common setup
  set $i=1
  while $i == 1
    set $i=0
    if ($argc == 0)
      # Some simple thing a few lines long
      ## What goes here so I exit mycmd?
      loop_break
    end

    # A lot of lines doing a complex thing
  end
end
于 2013-02-27T10:37:29.557 回答