Python gdb Breakpoint
Breakpoints can be changed by Python code using the gdb. class breakpoints
Any one of the two gdb forms can be used to generate a breakpoint.
Breakpoint builder. The first one can be used to generate both breakpoints as well as watchpoints because it accepts a string similar to what is passed to the break and watches commands (see Setting Breakpoints and Watchpoints). The second can only be utilized to establish breakpoints and accepts distinct Python arguments identical to Explicit Locations.
- Function: Breakpoint.__init__ (spec [, type ][, wp_class ][, internal ][, temporary ][, qualified ])
- In accordance with the specification, create a new breakpoint that is either an expression that designates a watchpoint or a string designating the location of a breakpoint. The string should specify a location in a format understood by the watch command or the break command if the location is a watchpoint (see Setting Breakpoints) (see Setting Watchpoints).
- The breakpoint's type is specified by the optional type argument, which is defined below.
- If the type is gdb, the optional wp _class parameter specifies the sort of watchpoint to construct.
- If wp_class is omitted, gdb is used by default. WP_ WRITE.
- The breakpoint can be made invisible to the user by using the optional internal argument. When a breakpoint is created, it won't report any information, and info breakpoints won't list it in the output anyway (but will be listed with the main info breakpoints command).
- The breakpoint becomes a temporary breakpoint when the optional temporary parameter is used. Once reached, temporary breakpoints are removed. After the Python breakpoint has been reached, any more access will results in a runtime error (as that breakpoint has now been automatically deleted).
- A boolean that can be used to interpret the function supplied in spec as a fully-qualified name is the optional qualified parameter. It is comparable to the -qualified flag in the break (see Linespec Locations and Explicit Locations).
- Function: Breakpoint.__init__ ([ source ][, function ][, label ][, line ], ][ internal ][, temporary ][, qualified ])
The explicit location is specified using keywords in this second method of adding a new breakpoint (see Explicit Locations). The new breakpoint will be set up at the specified function, label, and line in the source file that has been specified.
The same application applies to internal, temporary, and qualified.
- Function: Breakpoint.stop (self)
- You can subclass the gdb.Breakpoint class and one option are to add the stop method. When the inferior reach any place of a breakpoint that instantiates the sub-class, if this method is defined in that sub-class of gdb.Breakpoint, it is going to invoke. The inferior will halt at the breakpoint if the function returns True; else, the inferiority will continue.
- Multiple stop method breakpoints in the same place will all be invoked, regardless of the prior breakpoint's return status. This makes sure that every stop method has a chance to work there. In this case, the inferior method will still be used if one of the methods returns True but the others return False.
- You shouldn't affect the inferior's execution state (step, next, etc.), the context of the current frame (change the active frame), or change, add, or remove any breakpoints. In general, at this moment, you shouldn't change any data in gdb or even the inferior.
The gdb module defines the watchpoint kinds that can be used and are represented by constants:
- WP READ
simply read watchpoint
- WP WRITE
Only write watchpoint.
- WP_ACCESS
Write/Read a watchpoint.
Methods:
- Function: Breakpoint.is_valid ()
If such a Breakpoint object is legitimate, return True; otherwise, return False. Invalidation of a Breakpoint object might occur if the user removes the Breakpoint. The item is still present in this instance, but the underlying breakpoint is gone. When a watchpoint has a scope, the watchpoint is still in effect even if the inferior is executed outside of it.
- Function: Breakpoint.delete
removes the gdb breakpoint indefinitely. Additionally, a Python Breakpoint object is rendered invalid by this. Any more attempts that access this object's attributes and methods will result in a failure.
- Variable: Breakpoint.enabled
If the breakpoint is activated, this attribute is True; otherwise, it is False. This characteristic can be modified.
- Variable: Breakpoint.silent
If a breakpoint is silent, this characteristic is True; otherwise, it is False. This characteristic can be modified.
- Variable: Breakpoint.pending
If a breakpoint is active, this characteristic is True; otherwise, it is False. Look at Set Breaks. This characteristic only supports reading.
- Variable: Breakpoint.thread
This variable contains the thread's global id if the breakpoint is thread-specific. This value is None if the breakpoint isn't really thread-specific. This characteristic can be modified.
- Variable: Breakpoint.task
This variable contains the Ada task id is if the breakpoint is Ada task-specific. This variable is None if the breakpoint isn't really task-specific or if Ada is not the underlying language. This characteristic can be modified.
- Variable: Breakpoint.ignore_count
The breakpoint's ignore count, an integer, is stored in this attribute. This characteristic can be modified.
- Variable: Breakpoint.number
The breakpoint's number, which serves as the user's identifier when manipulating the breakpoint, is stored in this attribute. This attribute cannot be modified.
- Variable: Breakpoint.type
The breakpoint's type, which serves as the identifier for such actual breakpoint category or use-case, is stored in this attribute. This attribute cannot be modified.
- Variable: Breakpoint.visible
This attribute indicates whether the user can see the breakpoint when it is set or when the 'info breakpoints' command is executed. This attribute cannot be modified.
- Variable: Breakpoint.temporary
The existence of a temporary breakpoint is indicated by this characteristic. After that breakpoint is reached, temporary breakpoints were automatically eliminated. After the breakpoint has been reached, access to this attribute and any other attributes and functions besides the valid function will result in an error. This attribute cannot be modified.
- Variable: Breakpoint.hit_count
The integer hit count for a such breakpoint is stored in this attribute. Although this attribute can presently only be set to zero, it is editable.
- Variable: Breakpoint.location
The breakpoint's location, as defined by the user, is stored in this attribute. It's a string. The attribute's value is None if the breakpoint is a watchpoint and lacks a location. This attribute cannot be modified.
- Variable: Breakpoint.expression
A breakpoint expression that the user has given is stored in this attribute. It's a string. The attribute's value is None if the breakpoint lacks an expression (i.e., if it is not a watchpoint). This attribute cannot be modified.
- Variable: Breakpoint.condition
The breakpoint condition entered by the user is stored in this attribute. It's a string. The value of this attribute is None when there is no condition. This characteristic can be modified.
- Variable: Breakpoint.commands
The commands that are linked to the breakpoint are stored in this attribute. If commands are present, the value of this property is a string with each command separated by a newline. This attribute will be None if there are no commands. This characteristic can be modified.