Archive for December, 2007

Web site template - 748 Part VI . Programming in Linux It

Friday, December 21st, 2007

748 Part VI . Programming in Linux It would be helpful, however, to have some idea of the context in which the offending line(s) of code exist. For this purpose, use the list command, which takes the general form, list [m,n], where m and n are the starting and ending line numbers you want displayed. For example: (gdb) list 10,32 would display code lines 10 through 32. A bare list command displays 10 lines of code that includes the line where the error was first detected, as illustrated here: (gdb) list 15 index_to_the_moon(intary); 16 17 exit(EXIT_SUCCESS); 18 } 19 20 void index_to_the_moon(int ary[]) 21 { 22 int i; 23 for (i = 0; i < BIGNUM; ++I { 24 ary[i] = i; Examining Data One of GDB s most useful features is its ability to display both the type and the value of almost any expression, variable, or array in the program being debugged. It can print the value of any expression legal in the language in which your program is written. The command is, predictably enough, print. Here are a couple of print commands and their results: (gdb) print i $1 = 724 (gdb) print ary[i] Cannot access memory at address 0xc0000000. This example continues the earlier examples of debugging debugme.c because you are still trying to identify where and why debug me crashed. Although in this example, the program crashed at the point when the counter variable i equaled 724 (the expression $1 refers to an entry in GDB s value history, explained in a moment), where it crashes on your system depends on the system s memory layout, the process s memory space (especially the kernel s stack space), the amount of available memory on your system, and other factors. The result of the second command (print ary[i]) makes it pretty clear that the program does not have access to the memory location specified, although it does have legal access to the preceding one.
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Chapter 28 . Programming Tools and Utilities 747 (Ftp web hosting)

Thursday, December 20th, 2007

Chapter 28 . Programming Tools and Utilities 747 This short output listing shows that the segmentation fault occurred in the function index_to_the_moon at line 24 of debugme.c. Notice the last line of the output; GDB displays the line of code, prefixed with the line number (24), where the segmentation fault occurred. It also shows the memory address (in hexadecimal format) at which the fault occurred, 0xbffff4b0. You can pass any arguments to the run command that your program would ordinarily accept. GDB also creates a full shell environment in which to run the program. Ordinarily, GDB uses the value of the environment variable $SHELL to create the simulated environment. If you want, however, you can use GDB s set and unset commands to set or unset arguments and environment variables before you use the run command to run the program in the debugger. To set command-line arguments to pass to the program, type set args arg1 arg2, where arg1 and arg2 (or any number of arguments) are options and arguments the program being debugged expects. Use set environment env1 env2 to set environment variables (again, env1 and env2 are placeholders for the environment variables you want to set or unset). Inspecting Code in the Debugger What is happening in the function index_to_the_moon that s causing the error? You can execute the backtrace (or bt or back) command to generate the function tree that led to the segmentation fault. The backtrace doesn t usually show you what the problem is, but it does show you more precisely where the problem occurred. Here s how the function trace for the example looks on my system: (gdb) backtrace #0 0×080483db index_to_the_moon (ary=0×7ffffc90) at debugme.c:24 #1 0×080483a6 in main (argc=104,argv=0×69) at debugme.c:15 A backtrace shows the chain of function calls that resulted in the error. The backtrace starts with the most recently called function index_to_the moon() in this case which resides at the hexadecimal memory address shown in the second column of the display (0×0800483db). index_to_the_moon() was called by the main() function. As you can see from the output, the most recently called function was index_to_the_moon(), so, somewhere in the function, the segmentation fault occurred. Incidentally, the backtrace also shows that index_to_the_moon() was called from line 15 of the main() function in debugme.c. It s not necessary to type complete command names while using GDB. Any sufficiently unique abbreviation works. For example, back suffices for backtrace. Tip
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

746 Part VI . Programming in Linux After (Free web hosting services)

Wednesday, December 19th, 2007

746 Part VI . Programming in Linux After GDB initializes, the screen should resemble the one shown in Figure 28-1. Figure 28-1: GDB s startup screen. As you can see near the middle of the figure, GDB displays the name of the executable that created the core file: ` _ . Obviously, the displayed name is wrong; it should be debugme. The odd characters and the incorrect program name would give an experienced developer an immediate clue that the program has a significant memory bug. The next line in the figure, the text that reads Program terminated with signal 11, Segmentation fault explains why the program terminated. A segmentation fault occurs anytime a program attempts to access memory that doesn t explicitly belong to it. GDB also helpfully displays the function it was executing, index_to_the_moon, and the line it believes caused the fault (line 24). If you don t like the licensing messages (they annoy me), use the -q (or –quiet) option when you start GDB to suppress them. Another useful command-line option is -d dirname, where dirname is the name of a directory, which tells gdb where to find source code (it looks in the current working directory by default). After you load the program and its core dump into the debugger, run the program in the debugger. To do so, type the command run at the GDB command prompt, (gdb), as the following example shows: (gdb) run Starting program: /home/kwall/code/debugme Program received signal SIGSEGV, Segmentation fault. 0×0804483db in index_to_the_moon (ary=0xbffff4b0) at debugme.c:24 24 ary[i] = i; Tip
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Chapter 28 . Programming Tools and Utilities 745 (Web site directory)

Wednesday, December 19th, 2007

Chapter 28 . Programming Tools and Utilities 745 Listing 28-5: A Buggy Program /* * debugme.c - poorly written program to debug */ #include #define BIGNUM 5000 void index_to_the_moon(int ary[]); int main(int argc, char *argv[]) { int intary[100]; index_to_the_moon(intary); return 0; } void index_to_the_moon(int ary[]) { int i; for (i = 0; i < BIGNUM; ++i) ary[i] = i; } Compile this program using the command gcc -g debugme.c -o debugme. Then, execute the program using the command ./debugme. $ ./debugme Segmentation fault (core dumped) $ file core core: ELF 32-big LSB core file Intel 80386, version 1 (SYSV ), SVR4-style, SVR4-stylee, from debugme On most systems, when you execute ./debugme, it immediately causes a segmentation fault and dumps core, as shown in the output listing. If you don t see the core dumped message, try executing the shell command ulimit -c unlimited, which allows programs to drop a memory dump in their current working directory. The program has a bug, so you need to debug it. The first step is to start GDB, using the program name, debugme, and the core file, core, as arguments: $ gdb debugme core
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

744 Part VI . Programming in (Bulletproof web design) Linux Finally,

Tuesday, December 18th, 2007

744 Part VI . Programming in Linux Finally, if you totally botch all of your changes to your working files and want to revert to the most recent versions, use the update command. It updates the specified directory with the most recent versions stored in the repository, as shown in the following example: $ cd ~/projects/newhello $ cvs update . cvs udate: Updating . U showit.c U msg.c U hello.c There s much more to CVS than the few examples presented here. For additional information, visit the CVS home page on the Web at www.cvshome.org. Debugging with GDB Software is buggy, and some programs have more bugs than other programs. While debugging sessions will never be aggravation-free, GDB s advanced features lighten the load and enable you to be more productive in squashing bugs. Time and effort invested in learning GDB is well spent if you can track down and fix a serious bug in just a few minutes. GDB can make this happen. Most of what you will need to accomplish with GDB can be done with a surprisingly small set of commands. The rest of this chapter explores GDB features and shows you enough GDB commands to get you going. Effective debugging requires that your source code be compiled with -g option to create a binary with an extended symbol table. For example, the following command: $ gcc -g file1 file2 -o prog causes prog to be created with debugging symbols in its symbol table. If you want, you can use GCC s -ggdb option to generate still more (GDB-specific) debugging information. However, to work most effectively, this option requires that you have access to the source code for every library against which you link. While this can be very useful in certain situations, it can also be expensive in terms of disk space. In most cases, you can get by with the plain -g option. Starting GDB To start a debugging session, simply type gdb progname, replacing progname with the name of the program you want to debug. Using a core file is optional but will enhance GDB s debugging capabilities. Of course, you ll need a program on which to try out GDB debugging, so Listing 28-5 provides one: debugme.c.
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Chapter 28 . Programming Tools and (Best web site) Utilities 743

Monday, December 17th, 2007

Chapter 28 . Programming Tools and Utilities 743 When you check in a modified file, CVS opens an editor session to enable you to enter a log message that describes the changes you made. The editor used is the editor defined in the $EDITOR environment variable or compiled-in default (usually vi) if $EDITOR is undefined. This example did not use the -d option because the $CVSROOT environment variable is set. To check out a specific version, or revision, of a file, use the -r option following the checkout or co command, followed by a revision number. For example, to check out revision 1.1 of the showit.c file, use the following command: $ cvs checkout -r 1.1 newhello/showit.c U newhello/showit.c To see the differences between two revisions, use the diff command, using the -r m.n, where m.n indicates the revision number you want to check. If you specify -r only once, the indicated version will be diffed against the working file. If you specify -r twice, the two versions will be diffed against each other. The following example compares revision 1.2 of showit.c to the current working revision (the revision that is currently in the working directory): $ cvs diff -r 1.2 newhello/showit.c Index: newhello/showit.c =================================================================== RCS file: /space/cvs/newhello/showit.c,v retrieving revision 1.2 retrieving revision 1.3 diff -r1.2 -r1.3 9,10c9,10 < char msg_hi[] = { Hi there, programmer!n }; < char msg_bye[] = { Goodbye, programmer!n }; --- > char msg_hi[] = { Hi there, programmer! }; > char msg_bye[] = { Goodbye, programmer! }; 12c12 < printf( %s , msg_hi); --- > printf( %sn , msg_hi); The diff output is easier to understand than you might expect. Lines that begin with < appear in the first file (revision 1.2 of showit.c) but not in the second (revision 1.3 of showit.c. Similarly, lines beginning with > appear in the second file but not in the first. Each section of diff output begins with an alphanumeric sequence such as 9,10c9,10 or 12c12. The numeric values indicate the lines in the first and second files to which an operation must be applied to get the second file from the first. The operation to perform, such as inserting, deleting, or changing lines, is specified by the alphabetic character. So, for example, the sequence 9,10c9,10 means that to create the second file from the first you have to change (c) lines 9 and 10 of the first file to lines 9 and 10 of the second file.
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

X web hosting - 742 Part VI . Programming in Linux 6.

Saturday, December 15th, 2007

742 Part VI . Programming in Linux 6. Do as the instructions recommend; execute the command cvs commit to make the added files and directories permanent: $ cvs commit cvs commit: Examining . RCS file: /space/cvs/newhello/hello.c,v done Checking in hello.c; /space/cvs/newhello/hello.c,v <-- hello.c initial revision: 1.1 done RCS file: /space/cvs/newhello/msg.c,v done Checking in msg.c; /space/cvs/newhello/msg.c,v <-- msg.c initial revision: 1.1 done RCS file: /space/cvs/newhello/showit.c,v done Checking in showit.c; /space/cvs/newhello/showit.c,v <-- showit.c initial revision: 1.1 done Notice that CVS uses RCS file-naming conventions to work with files in the repository. This is because CVS was built on top of RCS and retains compatibility with the basic RCS feature set. CVS handles checking files in and out slightly differently than RCS. When checking a file out, it isn t necessary to specifically request a lock to get a writable copy of the file. To work on a file, you do need to use the checkout or co command: $ cd ~/projects $ cvs -d /space/cvs co newhello cvs checkout newhello U newhello/hello.c U newhello/msg.c U newhello/showit.c The checkout command used in this example specifies the path to the repository using the -d option. This is unnecessary if you set the $CVSROOT environment variable. After you have made changes to files, you can check them in using the cvs commit command (commit is comparable to RCS s ci command): $ cd ~/project/newhello $ cvs commit . cvs commit: Examining . [editor session] Checking in showit.c; /space/cvs/newhello/showit.c,v <-- showit.c new revision: 1.2; previous revision: 1.1 done
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

Chapter 28 . Programming Tools and Utilities 741 (Sri lanka web server)

Friday, December 14th, 2007

Chapter 28 . Programming Tools and Utilities 741 The Concurrent Versions System (CVS) supports both centralized repositories and network-based access. It is well-suited for use by multiple programmers, and a single CVS repository can support multiple projects. To keep the discussion simple, however, the example in this chapter deals only with a repository accessed locally. The following steps resemble the process described earlier for RCS, but they are slightly more involved and obviously use CVS concepts. 1. Create a CVS repository: $ mkdir /space/cvs $ export CVSROOT=/space/cvs $ cvs init The first command creates a directory named /space/cvs in which to establish the repository. The second command defines the environment variable $CVSROOT with this directory. Defining $CVSROOT makes using CVS much simpler. The third command initializes the repository, which creates some administrative directories CVS needs to work properly. 2. Create a top-level working directory in which to store your various projects and then cd into it: $ mkdir projects $ cd projects 3. Check out a copy of the CVS root directory into the top-level projects directory you just created: $ cvs -d $CVSROOT co -l . cvs checkout: Updating . The -d option tells cvs the directory containing the CVS repository ($CVSROOT, or /space/cvs); co means check out (just as with RCS); the -l option, which stands for local, means to work only in the current directory rather than recursing through subdirectories; and the . specifies the current directory. 4. Create a directory to hold a project and add it to the repository: $ mkdir newhello $ cvs add newhello Directory /space/cvs/newhello added to the repository 5. cd into the new directory, copy your project files into it, and then add those files (and any directories that might be present) to the repository: $ cp /projects/* . $ cvs add * Directory /space/cvs/newhello/debugme added to the repository cvs add: scheduling file `hello.c for addition cvs add: scheduling file `msg.c for addition cvs add: scheduling file `showit.c for addition cvs add: use cvs commit to add these files permanently
Check Tomcat Web Hosting services for best quality webspace to host your web application.

740 Part VI . Programming in Linux (Web hosting service) RCS s

Thursday, December 13th, 2007

740 Part VI . Programming in Linux RCS s command-line options are cumulative, as you might expect, and RCS does a good job of disallowing incompatible options. To check out and lock a specific revision of howdy.c, you would use a command like co -l -r2.1 howdy.c. Similarly, ci -u -r3 howdy.c checks in howdy.c, assigns it revision number 3.1, and deposits a read-only revision 3.1 working file back into your current working directory. The following example creates revision 2.1 of howdy.c. Make sure you have checked out and changed howdy.c somehow before executing this command. $ ci -r2 howdy.c RCS/howdy.c,v <-- howdy.c new revision: 2.1; previous revision: 1.2 enter log message, terminated with single . or end of file: >> Added something >> . done This command is equivalent to ci -r2.1 howdy.c. The next example checks out revision 1.2 of howdy.c, disregarding the presence of higher-numbered revisions in the working directory. $ co -r1.2 howdy.c RCS/howdy.c,v –> howdy.c revision 1.2 done The handy command shown next discards all of the changes you ve made and lets you start over with a known good source file. $ co -l -f howdy.c RCS/howdy.c,v –> howdy.c revision 2.1 (locked) done When used with ci, -f forces RCS to check in a file even if it has not changed. Source Code Control with CVS You may have noticed that RCS has some shortcomings that make it inadequate for use on large projects. First, without some sophisticated wrapper scripts to provide the directory handling machinery, RCS doesn t work very well with a single, centralized repository. Its repository is always the current directory unless you exert yourself to use a directory located elsewhere. More pertinent for Linux and other open source projects, RCS is utterly unsuitable for distributed development because it doesn t support network protocols. (That is, it doesn t work over the Internet.)
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Web site development - Chapter 28 . Programming Tools and Utilities 739

Wednesday, December 12th, 2007

Chapter 28 . Programming Tools and Utilities 739 With the file safely checked into the repository, you can check it out and modify it. To check a file out for editing, use the co command. Here s an example: $ co -l howdy.c RCS/howdy.c,v –> howdy.c revision 1.1 (locked) done The working file you just checked out is editable. If you do not want to edit it, omit the -l option. Making Changes to Repository Files To see version control in action, make a change to the working file. If you haven t already done so, check out and lock the howdy.c file. Change anything you want, but I recommend adding n to the end of fprintf() s string argument because Linux (and UNIX), unlike DOS and Windows, do not automatically add a newline to the end of console output. Then, check the file back in and RCS will increment the revision number to 1.2, ask for a description of the change you made, incorporate the changes you made into the RCS file, and (annoyingly) delete the original. To prevent deletion of your working files during check-in operations, use the -l or -u option with ci. Here s an example: $ ci -l howdy.c RCS/howdy.c,v <-- howdy.c new revision: 1.2; previous revision: 1.1 enter log message, terminated with single . or end of file: >> Added newline >> . done When used with ci, both the -l and -u options cause an implied check out of the file after the check-in procedure completes. -l locks the file so you can continue to edit it, while -u checks out an unlocked or read-only working file. Additional Command-Line Options In addition to -l and -u, ci and co accept two other very useful options: -r (for revision) and -f (force). Use -r to tell RCS which file revision you want to manipulate. RCS assumes you want to work with the most recent revision; -r overrides this default. The -f option forces RCS to overwrite the current working file. By default, RCS aborts a check-out operation if a working file of the same name already exists in your working directory. So if you really botch up your working file, use the -f option with co to get a fresh start.
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.