Using GNUPro Toolkit for development typically involves the following process.
See The C Run-time Environment (crt0).
See crt0, the Main Startup File.
See The Linker Script.
See Using RedBoot for Remote Debugging.
This chapter describes those steps in more detail.
When developing with a cross-configuration, you work with the tools on the host by using a toolchain . For example, working with a SPARCstation, you generate and debug code for a Power PC-based board by calling a specific tool with a specific embedded target's toolchain (this is described in more detail in Tools, Toolchains and Usage). The toolchain method has routines for providing a specific type of compiled output, others for preprocessing, and others for controlling assembling, linking, optimizing, debugging, and other target-specific functions.
When compiling, the following routines are for optimization:
When compiling, the following routines are for dynamic memory allocation:
newlib calls the following support routines, although not for embedded targets:
Most applications use calls to the standard C library. To link libc.a when you are developing with a target that has no operating system, you must first define several I/O functions, such as the open() and close() functions; for more information, see "System Calls" in GNUPro C Library in GNUPro Libraries .
When debugging, set up the tools as follows:
This type of embedded development may be inappropriate for real-time operating systems as embedded operating systems may provide their own configuration of tools.
When you use GNUPro tools, you typically use a standard convention for toolchain names. A toolchain name is a combination of a host name and a target name as a prefix to the tool name. The tables that follow provide the specific host and target names that you require. If you are not already familiar with the names of specific tools, review Compiler and Development Tools.
Before developing, use the configure command with the --exec= toolchain or --exec-prefix= toolchain option to specify in the Makefile the sources for the development environment.
To link and run C or C++ programs and to ensure that the system hardware initializes for C conventions before calling main , define a small module, crt0 (usually written in assembler as crt0.s ) to serve as your startup code. The startup code defines a special start symbol, the default address for your application, as well as the first symbol in the executable image. If you will use any routines from the standard C library, implement the functions upon which the library depends. To write your own crt0.s module, you need the following information about your target.
There are some examples available in the sources of GNUPro Toolkit for crt0.s code (along with examples of system calls with subroutines); look in the installdir /src/newlib/libc/sys path ( installdir refers to your installation directory; for example, look in .../sys/h8300hms for Hitachi H8/300 boards). More examples are in the installdir /src/newlib/stub directory.
At a minimum, your crt0.s module must provide the following processes to link and run your programs:
Choose where to store your stack within the constraints of your target's memory map, the simplest choice being a fixed-size area somewhere in the uninitialized data section (often bss ). Whether you choose a low address or a high address in this area depends on the direction your stack grows.
Use a linker script (see The Linker Script and "Linker Scripts" in Using ld in GNUPro Development Tools ) to define symbols such as bss_start and bss_end to record the boundaries of this section; then you can use a for loop to initialize all memory between them in the crt0.s module.
A more complete crt0.s module might also do the following:
The crt0 (C RunTime 0) file contains the initial startup code for embedded development; its object is linked in first and bootstraps the rest of your application. A crt0 file is available for most platforms, although you may want your own crt0 file for each target. The crt0 file is usually written in assembler and named crt0.s .
The crt0 file defines a special symbol such as _start , which is both the default base address for the application and the first symbol in the executable binary image.
If you plan to use any routines from the standard C library, you will also need to implement the functions on which newlib depends.
The crt0 file initializes everything that your program requires for the host and target. This initialization section varies for some systems:
The following shows a basic initialization of a crt0.s file; your file may differ, although there will be a similar initialization process.
These macros make the code portable between COFF and a.out ; COFF has _ _ (two underlines) before its global symbol names, while a.out has none.
3. Set up register names (with the appropriate prefix):
#ifndef _ _ REGISTER_PREFIX _ _
#define _ _ REGISTER_PREFIX _ _
#endif
/* Use the right prefix for registers. */
#define REG(x) CONCAT1 _ _ REGISTER_PREFIX _ _ , x)
#define d0 REG (d0)
#define d1 REG (d1)
#define d2 REG (d2)
#define d3 REG (d3)
#define d4 REG (d4)
#define d5 REG (d5)
#define d6 REG (d6)
#define d7 REG (d7)
#define a0 REG (a0)
#define a1 REG (a1)
#define a2 REG (a2)
#define a3 REG (a3)
#define a4 REG (a4)
#define a5 REG (a5)
#define a6 REG (a6)
#define fp REG (fp)
#define sp REG (sp)
Register names are for portability between assemblers. Some register names have % or $ prepended to them.
4. Set up space for the stack by assigning part of memory. (Although you can also set this allocation in the linker script, it typically is done at this point.)
5. Define empty space for an environment:
This call is unlike most for a ROM monitor. Generally it is best to set up a valid address and then pass the address to main() . In this way if an application checks for an empty environment, it finds one.
6. Set up a few global symbols:
The last line really should not be SYM (_ _bss_start) , since declaring _ _bss_start this way ensures the appropriate setting of its value in the linker script.
7. Set up the start global symbol for the linker to use as the default address for the .text section. This helps your program run.
Applications can get unpredictable effects with the .bss section left uncleared, causing particular problems with some implementations of malloc() calls.
Both rom68k and bug can handle an exception of 0 with no side effects; although the bug monitor has a user-caused trap that returns control to the ROM monitor, the bug monitor is more portable.
In the /usr/redhat/host/target/lib/ldscripts/ path, find the example linker scripts (host signifies your host configuration and target signifies the embedded configuration that you target). In that directory there will be files with the .x , .xbn , .xn , .xr , .xs , and .xu extensions serving as examples of linker scripts.
The linker script does the following:
When your application loads into memory, it allocates some RAM, some disk space for I/O, and some registers. The linker script makes a memory map of this memory allocation. This is important to embedded systems because you gain the ability to manage the behavior of the chip, even though they have no OS.
Actual section names vary depending on your object file format. For a.out and COFF formats, .text , .data , and .bss are the three main sections.
There are two ways to ensure the memory map is correct.
The following example shows how to set up a linker script for a Motorola 68000 target.
By default, the Motorola 68000 configuration using the COFF object file format does not link in
crt0.o
because it assumes that you have a
crt0
file. A
config
file controls this behavior in each architecture in a
STARTFILE_SPEC
macro. If you have
STARTFILE_SPEC
set to
NULL
, the GNU compiler formats its command line and does not add
crt0.o
. You can specify any filename with
STARTUP
, although the default is always
crt0.o
. If you use only
ld
to link, you control whether or not to link in
crt0.o
on the command line.
If you have multiple
crt0
files, you can omit
STARTUP
and link in
crt0.o
in a makefile or by using different linker scripts (this option is useful when initializing floating point values or when adding device support).
In this case, the file is a relocated library containing the definitions for the low-level functions that the libc.a file requires.
In the following example, it is only a pointer to the beginning of free RAM space with an upper limit at 2MB. If the output file exceeds the upper limit, MEMORY produces an error message.
In this example, you set up the memory map of the board's stack for high memory for both the rom68k and mon68k monitors.
SECTIONS
{
.text :
{
CREATE_OBJECT_SYMBOLS
*(.text)
etext = .;
_ _
CTOR_LIST
_ _
= .;
LONG((
_ _
CTOR_END
_ _
-
_ _
CTOR_LIST
_ _
) / 4 - 2)
*(.ctors)
LONG(0)
_ _
CTOR_END
_ _
= .;
_ _
DTOR_LIST
_ _
= .;
LONG((
_ _
DTOR_END
_ _
-
_ _
DTOR_LIST
_ _
) / 4 - 2)
*(.dtors)
LONG(0)
_ _
DTOR_END
_ _
= .;
*(.lit)
*(.shdata) }
> ram
.shbss SIZEOF(.text) + ADDR(.text) : {
*(.shbss)
}
In a COFF file, all of the actual instructions for setting up the constructor and destructor tables for the GNU C++ compiler are in .text . The section description redirects itself to the RAM variable that you previously set (see Set _stack, the variable for specifying RAM for the ROM monitor.) with the _stack variable.
A COFF file is where all of the initialized data goes. CONSTRUCTORS is a special command that the GNU linker, ld , uses.
The default values for _bss_start and _end are for use by the crt0 file when it zeros the .bss section.
.bss SIZEOF(.data) + ADDR(.data) :
{
_ _
bss_start = ALIGN(0x8);
*(.bss)
*(COMMON)
end = ALIGN(0x8);
_end = ALIGN(0x8);
_ _
end = ALIGN(0x8);
}
.mstack : { } > ram
.rstack : { } > ram
.stab . (NOLOAD) :
{
[ .stab ]
}
.stabstr . (NOLOAD) :
{
[ .stabstr ]
}
}
For more information on linking, see Using ld in GNUPro Development Tools .
This section discusses the architecture underlying the Cygwin tools for porting UNIX applications to Windows 32-bit environments. For more information, see:
http://sources.redhat.com/cygwin/
GNUPro Toolkit provides the following packages for Cygwin:
Cygwin emulates a standard UNIX directory structure. To emulate the /etc directory (so that the ls -l UNIX directory contents listing command works), use the following example's declarations as a guide:
mkdir /etc/
cd /etc
mkpasswd > /etc/passwd
mkgroup > /etc/group
Cygwin comes with both bash.exe and sh.exe shells. sh.exe is based on ash . In case of trouble with ash , make sh.exe point to the bash.exe shell.
When executing a binary linked against the library, the Cygwin dynamically linked library (DLL) loads into the application's text segment. To emulate a UNIX kernel for allowing access to all processes that can run with it, use the Cygwin DLL. The Cygwin DLL will create shared memory areas so that other processes using separate instances of the DLL can access the kernel. The DLL keeps track of open file descriptors and, among other purposes, assists fork and exec calls. In addition to the shared memory regions, every process also has a per-process structure that contains information such as process ID, user ID, signal masks, and other similar process-specific information.
The DLL uses the Win32 API. Because processes run under the standard Win32 subsystem, they can access both the UNIX compatibility calls provided by Cygwin as well as any of the Win32 API calls. This gives the programmer complete flexibility in designing the structure of their program in terms of the API in use; for example, a project might require a Win32-specific GUI using Win32 API calls on top of a UNIX back-end that uses Cygwin.
The CYGWIN environment variable helps to override the Win32 default behavior and force POSIX1 standards compliance.
UNIX applications that have to switch the user context have the setuid and seteuid calls, which are not part of the Microsoft Windows API. Nevertheless these calls are supported under Windows Microsoft Windows NT and Microsoft Windows 2000 with Cygwin.
Before using Cygwin tools, see descriptions of Mount Table and the mount Utility (below), Text and Binary Modes with Cygwin, File Permissions With Cygwin, Special Cygwin File Names, Building and Using DLLs with Cygwin, and Defining Windows Resources for Cygwin.
The mount utility controls a mount table for emulating a POSIX view of a Windows file system space. To change a Windows path that uses / and mount arbitrary Win32 paths into the POSIX file system space, use mount to mount each drive letter under a slash partition (such as C:\ to /c or D:\ to /d , and so forth).
Executing the mount command without any arguments prints the current mount table to a screen. Alternatively, provide the intended Win32 path to mount as a first argument and the POSIX path as the second argument.
Using the following command will remove all mount points.
Using mount demonstrates mounting C:/cygwin/H-i686-pc-cygwin/bin to /bin (assuming /bin exists), as well as mounting \\pollux\home\joe\data to a /data network directory, making /bin/sh a valid shell, to satisfy make .
With a bash shell, the forward slash will not work; substitute / or use single quotes.
This section discusses the main distinctions between text and binary modes with UNIX and Microsoft Windows interoperability, and how Cygwin solves the problems.
On a UNIX system, when an application reads from a file it gets exactly what is in the file on disk and the same is true for writing to the file. The situation is different in the DOS and Microsoft Windows world where a file can be opened in one of two modes, either binary or text. In the binary mode, the system behaves exactly as in UNIX. However in text mode there are major differences:
The mode can be specified explicitly. In an ideal DOS and Microsoft Windows world, all programs using lines as records (such as bash , make , or sed ) would open files (changing the mode of their standard input and output) as text. All other programs (such as cat , cmp , or tr ) would use binary mode. In practice with Cygwin, programs that deal explicitly with object files specify binary mode (as is the case of od , which is helpful to diagnose CR problems). Most other programs (such as cat , cmp , tr ) use the default mode. The Cygwin system gives us some flexibility in deciding how files are to open when the mode is not specified explicitly:
The CYGWIN environment variable will affect a disk file when you are using stdio redirection from the Microsoft Windows prompt. Otherwise, the mode of the file is based on the mode specified by a --change-cygdrive-prefix call, as the following example shows (which makes the default mode be binary).
If the file is a symbolic link, the mode of the target file system applies.
When redirecting, the Cygwin shells uses the first three rules. For these shells, the relevant value of CYGWIN is that at the time the shell was launched and not that at the time the program is executed.
Non-Cygwin shells always pipe and redirect with binary mode. With non-Cygwin shells, the cat filename | program and program < filename commands are not equivalent when filename is on a text-mounted partition. To illustrate the various rules, the following example's script deletes carriage returns (CRs) from files by using the tr program, which can write only to standard output:
#!/bin/sh
# Remove \r from the files given as arguments
for file in "$@"
do
CYGWIN=binmode sh -c "tr -d \\\"\\\r\\\" < '$file' > c:tmpfile.tmp"
if [ "$?" = "0" ]
then
rm "$file"
mv c:tmpfile.tmp "$file"
fi
done
The script works irrespective of the mount because the second rule applies for the path, c:tmpfile.tmp . According to the fourth rule, CYGWIN must be set before invoking the shell. These precautions are necessary because tr does not set its standard output to binary mode. It would thus reintroduce \r when writing to a file on a text mounted partition. The desired behavior can also be obtained by using tr -d \r in a .bat file.
UNIX programs that have been written for maximum portability will know the difference between text and binary files and act appropriately under Cygwin. For those programs, the text mode default is a good choice. Programs included in official distributions should work well in the default mode.
Text mode makes it much easier to mix files between Cygwin and Microsoft Windows programs, since Microsoft Windows programs will usually use the carriage return/line feed (CR/LF) format. Unfortunately you may still have some problems with text mode. First, some of the utilities included with Cygwin do not yet specify binary mode when they should; cat will not work, for instance, with binary files (input will stop at ^Z , CRs will be introduced in the output). Second, you will introduce CRs in text files you write, causing problems when moving them back to a UNIX system.
If you are mounting a remote file system from a UNIX machine, or moving files back and forth to a UNIX machine, you can access them in binary mode since text files found there will normally be NL format anyway, and you would want any files put there by Cygwin programs to be stored in a format that the UNIX machine will understand. Remove CRs from all Makefiles and shell scripts and make sure that you only edit the files with DOS/Windows editors that can cope with binary mode files.
You can decide this on a disk by disk basis (for example, mounting local disks in text mode and network disks in binary mode). You can also partition a disk, for example by mounting c: in text mode, and c:\home in binary mode.
On Windows 98 systems, files are always readable, and Cygwin uses the native read-only mode to determine if they are writable. Files are executable if the filename ends with a .bat, .com, or .exe file extension, or if #! starts. Consequently, chmod can only affect the w mode, whereas it silently ignores actions involving the other modes. Under NT, file permissions default to the same behavior as Windows 98 systems. However, there is optional functionality in Cygwin that can make file systems behave more like files for UNIX systems; for instance, use the ntea option to the CYGWIN environment variable (see Environment Variables for Cygwin). When using ntea , Cygwin will start with basic permissions, storing POSIX file permissions in NT Extended Attributes . On NTFS partitions, the attributes can be stored sensibly inside the normal NTFS filesystem structure. However, on a FAT partition, NT stores extended attributes in a flat file at the root of the EA DATA. SF. file partition, which can grow to extremely large sizes if you have a large number of files on the partition, slowing the system processes. In addition, the EA DATA. SF. file can only be deleted outside of Windows because of its in use status. For these reasons, the use of NT Extended Attributes is off by default in Cygwin. Specifying ntea in CYGWIN has no effect for Windows 98 systems. Under NT, the [ -w filename ] test is only true if filename is writable across the board, such as with a chmod +w filename call.
This section discusses some special file naming usage by Cygwin.
Differentiate any two files by examining their inodes.
The GCC compiler produces a filename .exe executable when asked to produce filename , allowing many makefiles written for UNIX systems to work well under Cygwin. Unfortunately the install and strip commands do distinguish between filename and a filename .exe file. They fail when working on a non-existing filename even if filename .exe exists, thus breaking some makefiles. To solve this problem, write install and strip shell scripts to provide the .exe extension.
windres reads a Windows resource file ( *.rc ) and converts it to a .res COFF file. The syntax and semantics of the input file are the same as for any other resource compiler; see any publication describing the Windows resource format for details.
windres compiles a .res file to include all the bitmaps, icons, and other resources you need, into one object file. Omitting the -O coff declaration would create a Windows .res format file without linkable COFF objects. Instead, windres produces a COFF object, for compatibility with how a linker can handle Windows resource files directly, maintaining the .res naming convention.
For more information on windres , see Using binutils in GNUPro Auxiliary Development Tools .
The following documentation provides an example of how to build a .dll file, using a single file, myprog .c , for the program, myprog .exe , and a single file, mydll .c , for the contents of the .dll file, mydll .dll , then compiling everything as objects.
gcc -shared myprog.c -o mydll .dll -e _ mydll _init@12
Now, when you build your program, you link against the import library, with declaration's like the following example's commands.
This section discusses using the GNUPro compiler with Cygwin to compile as you would on UNIX.
To run the GNUPro compiler, use the following command in a shell console:
gcc hello.c -o hello.exe
hello.exe
Hello, World
Cygwin allows you to build programs with full access to the standard Windows 32-bit API, including the GUI functions (as defined in Microsoft publications); however, the process of building those applications is slightly different using the GNU tools instead of the Microsoft tools. Your sources will not need to change; just remove all __export attributes from functions and replace them as follows:
int foo (int)
__
attribute
__
((
__
dllexport
__
));
int
foo (int i)
For most cases, remove the __export attributes.
The Makefile is similar to any other UNIX-like or Cygwin Makefile. The only difference is that you use a gcc -mwindows declaration to link your program ( myapp .exe in the following example's script) into a GUI application instead of into a command line application.
myapp.exe :
myapp.o
myapp.res
gcc -mwindows
myapp.o
myapp.res -o $@
myapp.res :
myapp.rc resource.h
windres $< -O coff -o $@
Before you can debug your program, you need to prepare your program for debugging. Add a -g declaration to all the other flags you use when compiling your sources to objects, in order to add extra information to the objects (making them much bigger), and to provide critical information to the debugger regarding line numbers, variable names, and other useful things. These extra symbols and debugging data give your program information about the original sources so that the debugger can resolve the problems. Use declarations similar to the following:
gcc -g -O2 -c
myapp.c
gcc -g
myapp.c -o
myapp
To invoke gdb , use the gdb myapp.exe declaration (substituting the executable file's name for myapp). The copyright text displays followed by the (gdb) prompt, from which you can enter commands such as run or help .
If your program crashes and you are trying to determine why it crashed, the best thing to do is type run and let your program run. After it crashes, you can use the where command to determine where it crashed, or the info locals call to see the values of all the local variables. The print declaration lets you examine individual variables or a line to which pointers point. If your program is doing something unexpected, use the break command to tell the debugger to stop your program when the debugging process gets to a specific function or line number.
Using the run command, stop your program at a breakpoint, and use other gdb commands to look at the state of your program at that point, to modify variables, and to step through your program's statements one at a time.
Use the help command to get a list of all the commands to use, or see Debugging with GDB in GNUPro Debugger Tools .
Before starting bash , you must set some environment variables, some of which can also be set or modified inside bash . You have a .bat file where the most important ones are set before initially invoking bash. The fully editable .bat file installs by default in \..\cygwin\cygnus.bat and the Start menu points to it.
The most important environment variable is the CYGWIN variable. The CYGWIN variable is used to configure many global settings for the Cygwin runtime system. Initially you can leave CYGWIN unset or set it to tty using input like the following example's syntax in a DOS shell, before launching bash .
C:\..\> set CYGWIN=tty notitle
The PATH environment variable is used by Cygwin applications as a list of directories in which to search for executable files to run. Convert this environment variable, when a Cygwin process first starts, from a Microsoft Windows format ( C:\WinNT\system32;C:\WinNT ) to UNIX format ( /WinNT/system32:/WinNT ).
Set the PATH environment variable so that, before launching bash , it contains at least a bin directory: C:\..\cygwin\H-i686-pc-cygwin\bin .
make uses an environment variable, MAKE_MODE , for determining the use of Command.com or /bin/sh to run command lines. If you get errors from make with the /c not found message, set MAKE_MODE to UNIX with the following example's form.
C:\> set MAKE_MODE=UNIX
export MAKE_MODE=UNIX
The HOME environment variable is used by UNIX shells to determine the location of your home directory. This environment variable is converted from the Microsoft Windows format ( C:\home\bob ) to UNIX format ( /home/bob ) when a Cygwin process first starts. To prevent confusion, ensure that HOME and /etc/passwd agree on your home directory.
The TERM environment variable specifies your terminal type. It is set it to cygwin by default.
The LD_LIBRARY_PATH environment variable is used by the Cygwin function, dlopen () , as a list of directories to search for .dll files to load. This environment variable is converted from the Microsoft Windows format (that is, C:\WinNT\system32;C:\WinNT ) to UNIX format (that is, /WinNT/system32:/WinNT ) when a Cygwin process first starts.
The CYGWIN environment variable is used to configure many global settings for the Cygwin runtime system, using the following options.
Each option is separated by others with a space. Many options can be turned off by prefixing with no (such as nobar or bar options).
ntea may create additional large files on non-NTFS partitions. ntea only operates under Microsoft Windows NT. Off by default.
The CYGWIN environment variable uses the following options. Each option is separated by others with a space. To turn off any option, prefix it with no (such as the nobinmode for the binmode option).
The ntea option only operates under Windows NT. It may create additional large files on non-NTFS partitions.
If you are trying to debug a program running the GNU debugger, GDB, you can use remote debugging with RedBoot. For details about debugging with RedBoot, a wide set of tools for downloading and executing programs on embedded target systems, see: http://sources.redhat.com/ecos/docs-latest/redboot/redboot.html RedBoot helps with manipulating a target system's environment, for both product development (debug support) and for end product deployment (flash and network booting).
The following documentation serves as a general reference for debugging with GNUPro Toolkit's graphical user interface, Insight; for more information, see Insight's Help menu for discussion of general functionality and use of menus, buttons or other features; see also "Insight, GDB's Alternative Interface" and the "Examples of Debugging with Insight" documentation in GNUPro Debugger Tools (see http://www.redhat.com/docs/manuals/gnupro/ ).
Insight works as the default means for debugging; to disable the GUI, use the gdb -nw command for non-windowing command line work.
Insight launches, displaying the Source Window (Source Window, the main window interface for Insight).
The menu selections in the Source Window are File , Run , View , Control , Preferences , and Help . To work with the other windows for debugging purposes specific to your project, use the View menu or the buttons in the toolbar.
When the debugger runs, the button turns into the Stop button (Stop button).
The Stop button interrupts the debugging process for a project, provided that the underlying hardware and protocols support such interruptions. Generally, machines that are connected to boards cannot interrupt programs on those boards. In such cases, a dialog box appears as a prompt asking if you want to abandon the session and if the debugger should detach from the target.
For an embedded project, click Run ; then click Continue (Continue button); this ensures configuration between the target and the host is clear so that the debugging tools will work effectively.
When debugging a target, do not click on the Run button during an active debugging process, since using the Run button will effectively restart the session with all work unrecoverable.
For more information on Insight, see its Help menu. For examples of debugging session procedures for using Insight, see the following documentation (the content assumes familiarity with debugging procedures).
To specify how source code appears and to change debugging settings, from the Preferences menu, select Source .
To add identification codes to the debugger's table of processors, see the GDB Internals documentation, distributed with the source code.
To select a source file, or to specify what to display when examining a source file when debugging, use the following processes.
A breakpoint can be set at any executable line in a source file.
Executable lines are marked by a minus sign in the left margin of the Source Window . When the cursor is over a minus sign for an executable line, the cursor changes to a circle. When the cursor is in this state, a breakpoint can be set. The Breakpoints window is for managing the breakpoints: disabling them, enabling them, or erasing them; an enabled breakpoint is one for which the debugging session will stop, a disabled breakpoint is one which the debugging session ignores.
The following exercise steps you through setting four breakpoints in a function, as well as running the program and viewing changed values in local variables.
Clicking the line again will remove the breakpoint.
Select threads and set breakpoints on one or more threads when debugging a multi-threaded application with Insight.
Working with multiple threads does not function similarly on all embedded targets. When debugging C++ code, for instance, breakpoints and exceptions may not work on multiple threads.
A process can have multiple threads running concurrently, each performing a different task, such as waiting for events or something time-consuming that a program does not need to complete before resuming. The thread debugging facility allows you to observe all threads while your program runs. However, whenever the debugging process is active, one thread in particular is always the focus of debugging. This thread is called the current thread. The precise semantics of threads and the use of threads differs depending on operating systems. In general, the threads of a single program are like multiple processes, except that they share one address space (that is, they can all examine and modify the same variables). Additionally, each thread has its own registers and execution stack and, perhaps, private memory.