知方号

知方号

Debugging with GDB

Go to the first, previous, next, last section, table of contents.

Breakpoint command lists

You can give any breakpoint (or watchpoint or catchpoint) a series ofcommands to execute when your program stops due to that breakpoint. Forexample, you might want to print the values of certain expressions, orenable other breakpoints.

commands [bnum] ... command-list ...endSpecify a list of commands for breakpoint number bnum. The commandsthemselves appear on the following lines. Type a line containing justend to terminate the commands.To remove all commands from a breakpoint, type commands andfollow it immediately with end; that is, give no commands.With no bnum argument, commands refers to the lastbreakpoint, watchpoint, or catchpoint set (not to the breakpoint mostrecently encountered).

Pressing RET as a means of repeating the last GDB command isdisabled within a command-list.

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

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

If the first command you specify in a command list is silent, theusual message about stopping at a breakpoint is not printed. This maybe desirable for breakpoints that are to print a specific message andthen continue. If none of the remaining commands print anything, yousee no sign that the breakpoint was reached. silent ismeaningful only at the beginning of a breakpoint command list.

The commands echo, output, and printf allow you toprint precisely controlled output, and are often useful in silentbreakpoints. See section Commands for controlled output.

For example, here is how you could use breakpoint commands to print thevalue of x at entry to foo whenever x is positive.

break foo if x>0commandssilentprintf "x is %d ",xcontend

One application for breakpoint commands is to compensate for one bug soyou can test for another. Put a breakpoint just after the erroneous lineof code, give it a condition to detect the case in which somethingerroneous has been done, and give it commands to assign correct valuesto any variables that need them. End with the continue commandso that your program does not stop, and start with the silentcommand so that no output is produced. Here is an example:

break 403commandssilentset x = y + 4contend

Go to the first, previous, next, last section, table of contents.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至lizi9903@foxmail.com举报,一经查实,本站将立刻删除。