THREAD-ORIENTED DEBUGGING

Abstract: A method is provided for debugging a program thread without overwriting a breakpoint indicator that is substituted in the thread for an opcode of the thread. After reaching the breakpoint, the opcode is read into a dedicated register for utilization. A method is also provided for facilitating debugging of a thread while allowing at least one other thread to continue running.

Description: Thread-oriented debugging BACKGROUND OF THE INVENTION 1. Field of the Invention The invention relates to the debugging of computer programs and, in particular, to the capability of debugging multiple threads. 2. Description of Related Art Many different techniques are used for facilitating the debugging of computer programs. One common technique is to stop the running of a program thread (i.e. a sequence of instructions) upon the occurrence of a predetermined event and to examine the contents of various memory locations, e.g. registers, addresses in RAM, etc. A very useful device for stopping a thread in this manner is the breakpoint. Breakpoints for stopping execution of a currently-running thread can be set to occur in a variety of ways. Examples include breakpoints that occur when a specific instruction is executed and breakpoints that occur when a specific memory location is accessed. A representative example of using a specific-instruction type of breakpoint is illustrated in Figures 1 A through IF. Figure 1A illustrates a sequence of instructions in a thread to be debugged. Each of the instructions includes an opcode followed by any parameters (e.g. operands, addresses, data etc.) that are associated with the respective instruction. Typically, each opcode is one byte long. In this example, the sequence includes three instructions, i.e.: Instruction A, comprising opcode A followed by two associated paramaters Al and A2; Instruction B, comprising opcode B followed by one associated parameter Bl; and Instruction C, comprising opcode C followed by two associated parameters Cl and C2. Conventionally, each of these instructions is read and executed in the sequence shown under the control of a program counter in a processor. Figure IB shows how a breakpoint is set in the thread to be debugged. Specifically, a HALT opcode is substituted by the debugger in place of opcode B. Figure 1 C depicts the instant when the processor has executed Instruction A and has incremented the value PC in the program counter to the address where the HALT opcode is stored. At this time, the processor stops running the thread and directly or indirectly notifies the debugger that the breakpoint has been reached. This can be done in a variety of ways, e.g. by the processor activating an interrupt to the debugger or by the debugger periodically polling the state of the processor to detect that the processor has reached a HALT opcode. As is depicted in Figure ID, the debugger responds to notification of the HALT opcode by reading the value PC for the halted thread to determine which one (of possibly many) breakpoints has been reached. The debugger then writes the corresponding opcode (i.e. "opcode B", for which the HALT opcode had been substituted in Figure IB) into the memory 20 and commands the processor to execute the next instruction. In executing this instruction, the processor will read the newly- written opcode B and increment the program counter to indicate the location of the associated single-byte parameter Bl. As is depicted in Figure IE, the processor then reads the associated parameter Bl and increments the program counter to the address of opcode C. On completion of instruction B, the processor stops and the debugger regains control. As is depicted in Figure IF, after the processor executes Instruction B, but before it reads opcode C, the debugger re-substitutes the HALT opcode for opcode B in the program stream. This is necessary to retain the breakpoint in the thread. From the example shown in Figure 1 , it can be seen that breakpoint debugging of even a single thread can be a complicated and time consuming process. SUMMARY OF THE INVENTION It is an object of the invention to provide a method of breakpoint debugging that is simpler and less and time consuming than known breakpoint debugging techniques. It is yet another object of the invention to provide a method of debugging which, in a multi -threaded software environment, facilitates debugging of one thread while allowing other threads to continue running. In accordance with one form of the invention, a method of debugging a program thread, having a sequence of instructions to be run by a processor, includes: substituting a breakpoint indicator for a selected part of at least one of the instructions; saving the selected part in a predetermined memory location; sequencing through the instructions until the breakpoint indicator is reached; reading the selected part from the predetermined memory location without overwriting the breakpoint indicator; performing at least one of a plurality of predetermined debugging operations. In accordance with another form of the invention, a method of facilitating selective debugging of a plurality of program threads capable of being run by a processor includes: providing a running status indicator in a respective context for each of said threads; running each thread for which the status indicator is in a first state; not running each thread for which the status indicator is in a second state. Note that the word "memory", as used herein, is intended to be interpreted as generally as is consistent with the manner in which it is used and includes volatile and nonvolatile devices of various types including, without limitation, RAMs, DRAMs, ROMs, registers and combinations of such devices. A "dedicated" memory means that the memory has one or more specific locations which are known to the processor. However, these locations need not be fixed, but may be changed under the control of the processor. Also, as used herein, the word "pointer" means any value that identifies a memory location. Additionally, "accessing" data means obtaining data from, or placing data into, a memory. BRIEF DESCRIPTION OF THE DRAWING Figures 1 A through IF illustrate a known breakpoint technique. Figure 2 is a block diagram illustrating an exemplary processing system that is useful in explaining preferred embodiments of the invention. Figures 3 A through 3E illustrate a breakpoint technique in accordance with an embodiment of the invention. DESCRIPTION OF THE PREFERRED EMBODIMENTS The processing system of Figure 2 includes a processor 10 and a memory 20. The exemplary processor 10 is a hardware-accelerated unit, which utilizes clock pulses to sequence through instructions identified by a program counter register. Typically, the program counter register contains the memory location of the next instruction to be read and acted upon by the processor. The processor includes a context register set 12, an instruction decoder 14, an arithmetic logic unit 16, an SS OPCODE register 17, an SS TC PTR register 18, and a register 19 containing an OPCODE IS VALID flag. The memory 20, in this exemplary embodiment, comprises a RAM having a multiplicity of memory locations for storing, inter alia, a plurality of thread contexts. The processor 10 and the memory 20 are connected to a common bus 30 for communicating with each other and with other hardware that is connected to the bus. The bus includes respective lines for carrying information such as addresses, interrupts, data, read strobes, write strobes and device-select strobes. Preferably, this is a high-speed bus which is at least partially formed on a common silicon substrate with the processor and the memory. The context register set 12 comprises a plurality of registers for containing the context of the thread currently being run by the processor 10. In the preferred embodiment, the register set 12 includes: a program counter register 121 containing a value PC which the processor continually updates to identify the address of the next instruction in the memory 20 to be accessed; a register 122 for holding a pointer TC PTR indicating a memory address where the context for the thread currently being run by the processor is to be stored; a register 123 for holding STATUS information associated with the thread currently being run by the processor; and one or more additional registers 125 for holding, inter alia, additional thread- context information and data which is either read from the memory 20 or produced by the arithmetic logic unit 16. The instruction decoder 14 is a conventional hardware component, such as a sequencer or micro-sequencer, for converting the instructions read from the memory 20 to lower-level operation codes. The arithmetic logic unit 16 is also a conventional hardware component. The SS OPCODE register 17, the SS TC PTR register 18, and the SS OP FLAG register 19 are provided for holding information particularly relevant to breakpoint debugging. Specifically, register 17 holds an opcode from a thread that is being debugged (a debugee thread), register 18 holds a pointer SS TC PTR associated with the debugee thread, and register 19 holds a flag associated with register 17. In operation, the processor runs one thread at a time (the current thread), but can be switched to any other thread by a variety of means, e.g. by an internal timer interrupt, by an external interrupt, or by an instruction in the current thread itself. As is well known in the art, this is typically done by storing the current thread context (held in context register set 12) into the memory address indicated by the pointer TC PTR contained in register 122. The processor then reads into the context register set 12 the respective context for the next thread to be run. Figures 3 A through 3E generally illustrate an example of breakpoint debugging in accordance with an embodiment of the invention. The same sequence of instructions that were utilized in the known technique illustrated in Figures 1A through IF are used in this example to facilitate comparison. Figures 3 A through 3C are identical to Figures 1A through lC. That is, Figure 3 A illustrates the sequence before insertion of a breakpoint opcode; Figure 3B shows that the debugger has substituted the breakpoint opcode HALT; and Figure 3C depicts the instant when the processor has incremented the value PC in the program counter register 121 to the address where the HALT opcode is stored. At this time, the processor also stops running the thread and notifies the debugger that the breakpoint has been reached. As is depicted in Figure 3D, the debugger responds to notification of the HALT opcode by reading the value PC for the halted thread. Rather than writing opcode B (for which the HALT opcode had been substituted) over the HALT opcode, however, the processor writes opcode B into the SS OPCODE register 17, leaving the HALT opcode in the thread, and sets the OPCODE IS VALID flag. The processor then increments the program counter to indicate the location of the associated single-byte parameter Bl. As is depicted in Figure 3E, the processor reads the associated parameter Bl, increments the program counter to the address of opcode C, and executes the just-read instruction B. All of the steps which would have been needed to re-substitute the HALT opcode for opcode B are thus eliminated. This typically includes halting the processor on completion of instruction B, over-writing opcode B with the HALT opcode, and then resuming running of the stopped thread or a different thread. The specific manner in which breakpoint debugging is carried out will depend on the options provided to the debugger and the number of threads that the processor is running. In accordance with a preferred embodiment of the invention, the debugger is provided with the following options, all of which are available regardless of whether one or more threads is running: stop a running thread; single-step from a breakpoint or from a point other than a breakpoint; resume running from a breakpoint or from a point other than a breakpoint. In order to facilitate these options, flags and commands are provided for use by the debugger and the processor, including: a RUNNING flag, contained in the STATUS information for each thread, which indicates whether the respective thread is running or stopped; an OPCODE IS VALID flag, contained in register 19 which: when set, indicates that an opcode awaiting execution has been loaded into the SS OPCODE register 17; when reset, indicates that the next instruction should be taken from the program stream; a SINGLE-STEP command, which will cause the processor to execute the next instruction only in a stopped thread; a RESUME command, which will cause the processor to resume running of a stopped thread. If more than one thread is running, each thread being debugged will stop upon the occurrence of a HALT opcode and the RUNNING flag for that thread will be reset. The processor will continue to alternately process all threads, but each time it accesses the context for a stopped thread it will detect the reset state of the RUNNING flag in that thread's context and then do nothing until an interrupt occurs, causing the processor to switch to the next thread in sequence. The debugger may be debugging one or more threads, each having one or more breakpoints set. To respond to the occurrence of a HALT at a breakpoint, the debugger must be able to locate the opcode for which the HALT opcode was substituted. Preferably the debugger does this by having the processor notify it of the thread context address for the thread which processed the HALT instruction or by accessing the status register in the thread context for each debugee thread to sense the state of the RUNNING flags. Note that a reset, i.e. stopped, state may exist for more than one debugee thread at a time. Stop a Running Thread The debugger may choose to stop any thread which is running. To do this, the debugger will instruct the processor to load the SS TC PTR register 18 with a pointer identifying the memory location holding the context for the running debugee thread. The debugger will then issue the HALT command, causing the processor to: save the context of any currently-running thread in the memory address indicated by the pointer TC PTR which is currently in register 122; copy the contents of register 122 into register 18 (to facilitate later re- installation of the just-running thread) and copy the contents of register 18 (the pointer SS TC PTR) into register 122; read into the context register set 12 the debugee context located at the memory address identified by the pointer SS TC PTR (now in register 122); reset the RUNNING flag; save in memory the current context for the debugee thread that has just been stopped; copy the contents of register 18 into register 122, to effect re-installation of the previously-running thread; read into the context register set 12 the thread context located at the memory address identified by the pointer TC PTR in register 122. Note that the saved context in the debugee thread has the RUNNING flag reset. Thus the processor continues to cycle through all of the threads it is processing, but each time it reaches the context of the debugee thread it notes that the RUNNING flag in the STATUS information is still reset and does not run the debugee thread. Single-step The debugger may choose to single step any thread which is stopped. To do this, the debugger will instruct the processor to load the SS TC PTR register 18 with a pointer identifying the memory location holding the context for the stopped debugee thread. The debugger will then read the program counter for the debugee thread to determine whether it was stopped at a breakpoint. If at a breakpoint, it will load into the SS OPCODE register 17 the opcode for which the HALT opcode had been substituted (e.g. opcode B in Fig. 3D) and will set the OPCODE IS VALID flag. If not at a breakpoint, the OPCODE IS VALID flag will have already been reset. The debugger will then issue the SINGLE-STEP command, causing the processor to: save the context of any currently-running thread in the memory address indicated by the pointer TC PTR which is currently in register 122; copy the contents of register 122 into register 18 (to facilitate later re- installation of the just-running thread) and copy the contents of register 18 (the pointer SS TC PTR) into register 122; read into the context register set 12 the debugee context located at the memory address identified by the pointer SS TC PTR (now in register 122), which context includes the value PC for the breakpoint at which the HALT opcode resides; examine the OPCODE IS VALID flag to determine the source of the opcode to be used, i.e. from register 17 if the flag is set or from the program stream if the flag is reset; reset the OPCODE IS VALID flag to indicate that no opcode awaiting execution is in register 17; increment the value PC in register 121 (e.g. to the address of parameter Bl in Fig. 3D); read the parameter(s), if any, at the incremented value PC (e.g. the parameter Bl); repeat the last two steps as necessary to read any additional parameter(s) associated with the opcode read from register 17; execute the complete instruction formed from the just-read opcode, and any parameter(s) associated with it, and then increment the value PC to the next opcode (e.g. opcode C in Figure 3E); save in memory the current context for the debugee thread that has just been single stepped; copy the contents of register 18 into register 122, to effect re-installation of the previously-running thread; read into the context register set 12 the thread context located at the memory address identified by the pointer TC PTR in register 122. Note that the saved context includes the value PC for the next instruction to be executed in the debugee thread and the RUNNING flag, which is still reset. Thus the processor continues to cycle through all of the threads it is processing, but each time it reaches the context of the debugee thread it notes that the RUNNING flag in the STATUS information is still reset and does not run the debugee thread. Resume Running The debugger may choose to resume the running of any thread which is stopped. To do this, the debugger will instruct the processor to load the SS TC PTR register 18 with a pointer identifying the memory location holding the context for the stopped debugee thread. The debugger will then read the program counter for the debugee thread to determine whether it was stopped at a breakpoint. If at a breakpoint, it will load into the SS OPCODE register 17 the opcode for which the HALT opcode had been substituted (e.g. opcode B in Fig. 3D) and will set the OPCODE IS VALID flag. The debugger will then issue the RESUME command, causing the processor to: save the context of any currently-running thread in the memory address indicated by the pointer TC PTR which is currently in register 122; copy the contents of register 122 into register 18 (to facilitate later re- installation of the just-running thread) and copy the contents of register 18 (the pointer SS TC PTR) into register 122; read into the context register set the debugee context located at the memory address identified by the pointer SS TC PTR (now in register 122), which context includes the value PC for the breakpoint at which the HALT opcode resides; examine the OPCODE IS VALID flag to determine the source of the opcode to be used, i.e. from register 17 if the flag is set or from the program stream if the flag is reset; reset the OPCODE IS VALID flag to indicate that no opcode awaiting execution is in register 17; increment the value PC in register 121 (e.g. to the address of parameter Bl in Fig. 3D); read any parameter(s) at the incremented value PC (e.g. the parameter Bl); repeat the last two steps as necessary to read any additional parameter(s) associated with the opcode read from register 17; set the RUNNING flag in the STATUS information contained in register 123; execute the complete instruction formed from the just-read opcode, and any parameter(s) associated with it, and then increment the value PC to the next opcode (e.g. opcode C in Figure 3E); save in memory the current context for the debugee thread; copy the contents of register 18 into register 122, to effect re-installation of the previously-running thread; read into the context register set 12 the thread context located at the memory address identified by the pointer TC PTR in register 122. Alternatively, if not at a breakpoint, the OPCODE IS VALID flag will have already been reset. The debugger will then issue the RESUME command causing the processor to: save the context of any currently-running thread in the memory address indicated by the pointer TC PTR which is currently in register 122; copy the contents of register 122 into register 18 (to faciliate later re- installation of the just-running thread) and copy the contents of register 18 (the pointer SS TC PTR) into register 122; read into the context register set the debugee context located at the memory address identified by the pointer SS TC PTR (now in register 122), which context includes the value PC for the next opcode in the thread; set the RUNNING flag in the STATUS information contained in register 123 ; save in memory the current context for the debugee thread; copy the contents of register 18 into register 122, to effect re-installation of the previously-running thread; read into the context register set 12 the thread context located at the memory address identified by the pointer TC PTR in register 122. Note that the saved context includes the value PC for the next instruction to be executed in the debugee thread and the RUNNING flag (which is now set). Thus the processor continues to cycle through all of the threads it is processing, and each time it reaches the context of the debugee thread it notes that the RUNNING flag in the STATUS information is set and runs the debugee thread.

Claims: CLAIMS: 1. A method of debugging a program thread comprising a sequence of instructions to be run by a processor (10), said method comprising: a. substituting a breakpoint indicator (HALT) for a selected part (opcode B) of at least one of the instructions; b. saving the selected part (opcode B)in memory; c. sequencing through the instructions until the breakpoint indicator (HALT) is reached; d. reading the selected part (opcode B) from memory without overwriting the breakpoint indicator (HALT); e. performing at least one of a plurality of predetermined debugging operations. 2. A method as in claim 1 where the selected part is saved in and read from a predetermined memory location. 3. A method as in claim 1 where the selected part comprises an opcode. 4. A method as in claim 1 where the selected part comprises a HALT opcode for stopping running of the thread. 5. A method as in claim 1 where the predetermined debugging operations include: a. halting the running of the program thread at the breakpoint; b. single-stepping a halted thread; c. resuming running of a halted thread. 6. A method as in claim 1 where a flag is provided to indicate whether the selected part has been read into the dedicated memory and is awaiting utilization. 7. A method of facilitating selective debugging of a plurality of program threads capable of being run by a processor, said method comprising: a. providing a running status indicator in a respective context for each of said threads; b. running each thread for which the status indicator is in a first state; c. not running each thread for which the status indicator is in a second state. 8. A method as in claim 7 where a debugger utilizes the running status indicator to select a thread for debugging while allowing at least one other thread to continue running.

Inventors: ROSS KEVIN, SAVILLE WINTHROP L, ROSS, KEVIN, SAVILLE, WINTHROP, L.
Applicants: KONINKL PHILIPS ELECTRONICS NV, KONINKLIJKE PHILIPS ELECTRONICS N.V.
Application year: 2000
Main classification: G06F11
IPC codes: G06F9, G06F11