1

CEN 4020 Software Engineering Essay No. 1: Spring 2012 Active learning project: debugging methods Submission deadline: February 16, 2012

Full name: Lindsey Segal USFID: U68581935 E-mail: lsegal@mail.usf.edu

Abstract Debugging a program is an essential part of the software engineering process. Determining how to fix these errors quickly and efficiently is not only important for the users of these programs, but it also aids in improving the ability for a programmer to create in depth and correct code. Today, there are a variety of techniques that help novice and advanced developers, but there are still many areas related to debugging that could be improved on. In this report I will first begin by explaining the general principles of debugging, including what it is and why debugging is such an important area of interest. I will then describe the various methods available to fix programming bugs. Finally, I will show examples of debugging code and additional pieces of software that allow debugging to be less time intensive and more proficient. Key Terms Breakpoint Postmortem debugging On-line debugging Fault localization I. Introduction -Definition of debugging. Why this does not depict how important this area is. II. General Information According to Terence Parr, professor of computer science at the University of San Francisco, the debugging process can be divided into six steps. By following these guidelines, you can become a more efficient debugger by separating one big problem into smaller sections. Although this is still a challenging feat, there is peace of mind knowing that this is not one large task but instead smaller and less stressful components that can bring you to the final solution. This process includes: reproducibility, reduction, deduction, experimentation, experience, and tenacity [1].
i. Reproducibility CEN 4020 – Software Engineering: Essay No. 1

For example. Reduction This goal of this step is to reduce the amount of data necessary to reproduce the bug. Following this step can lead to a quick find for an error. If we CEN 4020 – Software Engineering: Essay No. Other time there are multiple bugs existing on multiple lines of code. which computes the difference between these executions. there was one single line that was longer than the rest. we use what Roychoudhury refers to as a difference metric. I personally have used this method to determine the cause of an error in a program. we realized that although the first half of the csv looked identical. Once we determine the runs to compare. if you have a large data file. The failed run is considered to be the executed program that produces some type of invalid or unexpected input. Figure 1. 1 . or at least reduce the amount of unneeded data to decipher. causing our program to output incorrectly. Fault Localization Methods.2 The main goal here is to find the error and reproduce the effect for further evaluation. My partner and I sat there for hours trying to determine the cause of our error when we decided to split up the data file into smaller sections. This method involves executing the program multiple times and then comparing the results against each other to determine where the error exists. then you know that the error is somewhere in the other half of the file. If you find that the error disappears after this split. Sometimes the bug exists in only one line of code. One way to replicate these bugs is through “fault localization through trace comparison” which is described in the report by University of Singapore student Abhik Roychoudhury [2]. you can split in half and use the first portion to debug your code. Below is an example of this method to reproduce and determine the location of the errors. which allows us to solve the problem easily. we were required to complete a project that used a csv file as our input into the program. or the bug appears intermittently during execution. Either way. The difference between the runs then determines what should be considered when determining where the bug is located. ii. During my Data Structures course. This is then compared with a successful run which is deemed correct if there is no unexpected behavior present. After doing this. replicating these errors in a reliable manner is vital to perform the entire debugging process.

we could have saved ourselves a lot of time and headaches trying to determine what we did wrong. The more you write code. Debugging Categories CEN 4020 – Software Engineering: Essay No. This easy debugging method is utilized by simply including print statements for some or all of the variables that may be associated with the error. Around this point is where experimentation would occur and also where novice programmers may implement the famous print statement technique. Becoming an experienced program debugger means that you have made mistakes. You are the main component in the debugging process and you must be the one to keep going no matter what. iii. Without the experimental step. Experimentation is vital in the determination of bugs because this is where you modify and change your code until you see a noticeable improvement in the output of your program. iv. Giving up will not help you improve your understanding of the programming and error checking processes. Also. we took the area where the error was occurring and located its corresponding code to correct this bug. 1 . The same goes for the area of debugging. I believe little would be understood in the area of debugging and even less for those just entering this ever expanding field. there is a light at the end of the tunnel that only you can get to. it does allow those with little programming or debugging experience to isolate the problem. but it helps you understand that although this may be a long and tedious process. Experience This next area may seem obvious. Although this is not a recommended technique. This also prevents you from making the same mistakes in the future and to catch mistakes before they cause major problems in your code. you can always learn from others and find new ways of doing things that may help your coding and debugging abilities in the future. Although experience comes with time. learning from those that are more experience than you can help improve your programming and debugging skills. In the example of my error in the data structures program. Deduction & Experimentation These two areas in the process are an accumulation of steps one and two. v.3 had decided to do this initially. it is important nevertheless. Being tenacious not only aids in your debugging abilities. the more you can understand the ins and outs of computer programming. Being a programmer means you must push forth even if you feel discouraged. which many believe to be equally important. Deduction is the area where you take the components causing the bug and determine where and why this is happening. but you have also learned from them. but you can never stress enough to those starting off as programmers the power of experience. Tenacity Although this may not be a definable step in the debugging process. III. if not more important than the program implementation itself.

you will never be able to successfully run your code. An example of a syntax error would be forgetting to capitalize a key word. Runtime errors can also be some of the most difficult to correct. missing semi-colons or missing curly brackets to surround your class or functions. ii. runtime. implying that there is something wrong with your declarations. Runtime Runtime errors are not visible until you execute your program. They can occur for multiple reasons. They may look similar. Debugging & Unit Testing The techniques used to debug programs are a part of a field that is still expanding. infinite loops. i. These peicies of code may look syntactically correct. and semantic errors which are discussed below. This is because the logic behind the code is invalid. CEN 4020 – Software Engineering: Essay No. Without first fixing these types of errors. These include syntax. you see these types of errors pop up. and progresses into the more advanced systems used to rid code of these unattractive errors. The ‘=’ operator assigns a value. while others can be a quite difficult to decipher. iii. but they are in fact very different. Semantic Semantic errors can also be referred to as logical errors. in Java if you capitalize the word ‘class’ or ‘int’. These are all possible causes because they are not visible at first to a programmer but once the code has been compiled and run. but once compiled the output produces invalid values. I know from personal experience that this is the area where I have always seen the majority of my errors. Computer scientists are still finding improvements in the current methods implemented and developing new ways to debug code in a more efficient and less manual manners. The section begins with the types of debugging preferences used by novice programmers. Syntax Syntactic errors are errors that are specific to the language you are writing your program in. Some other examples of syntax errors include missing arguments in a function call.4 In addition to the process of debugging. and pointer references. some including memory allocation. These errors are also known as exceptions because they refer to some type of exceptional occurrence that is causing bad or unexpected out. Some may be easy to fix. These errors are also very common for beginning programmers mainly because they haven’t had the proper experience related to programming logic. 1 . there are also three different categories within the realm of debugging. you will receive an error similar to “class or interface declaration expected”. IV. while the ‘==’ is a logical operator to check if two things are equal. One example of a semantic error is using the ‘=’ instead of the ‘==’ operator when doing a calculation. Using specific techniques is how many novice and advanced programmers can accomplish this area of debugging. If your syntax is off. the compiler will generate an error or warning telling you something is wrong. For example.

companies utilize test cases by having people test their programs before they are sent out to the customers. CEN 4020 – Software Engineering: Essay No. who created a file that inserted print statements for every variable and line in a program. “a debugger allows working through the code line-by-line to find out what is going wrong. iii. Although this made this method less cumbersome. The Debugger According to student P. in the end you were still seeing so many lines of output that in some cases it tended to confuse you more. It allows working interactively. For the novice. Since I began my career in the field of Computer Science. I have always chosen this technique as my primary choice when I found output that I did not intend to see. this would include inputting a letter when you should be entering a number. There are now new ways to debug code that are more useful and effective at determining the location and cause of an error without the manual insertion of print statements. stopping it at various times.5 i. Before the launch. This is further discussed in the section “Postmortem Debugging”. [4]” I think this definition perfectly sums up the concept of using the debugger. Although this can be an easy way to catch unexpected output or to check the values of your variables. as many programmers starting out do. it is still used by programmers of all levels of expertise. controlling the execution of the program. Test Case Scenarios This may not be a defined type of debugging but testing program functionality is definitely a valuable method to determine if your code is running correctly. The Print Statement This technique is one that has been used for many years and by many developers in the programming world. ii. 1 . debuggers can become your best friend when a program goes awry. but it certainly is not efficient. The way this method works is by inserting print statements into your source code so that you can see an output of values for every variable you believe to be the culprit behind your errors. Additionally. Adragna of the University of London. which can be very important if there are semantic errors that are not directly visible in your code. changing code flow whilst running. inspecting variables. If you choose to use print statements you may output more code than you need to determine the cause of your error. where and why. This method also allows you to track the flow of your program. I mainly chose this method for its simplicity. Too many print statements can bog down your code. making it either unreadable or overwhelming. Although many people believe this technique is outdated and inefficient. Without this step it is possible that a piece of software could be sent out into the world with bugs which could be extremely problematic. this type of debugging technique can be very helpful when launching new software to multiple users. it is not as efficient as one would desire. Once you develop a sense of how they work. Debugging code in this manner can help programmers find errors that they may not have anticipated to occur. or attempting to max out an array. One example of this comes from my former programming partner.

Postmortem Debugging Postmortem debugging is extremely useful for companies employing software on multiple systems or to a large group of customers. When a program crashes. the start of a function or loop. CEN 4020 – Software Engineering: Essay No. or step over specific areas in your program. you would not be executing the code but taking that block and basically ignoring it. According to David Pacheco. Using breakpoints also helps you to see what the compiler is seeing. Using print statements forces you to manual insert temporary lines into your code in order to determine where the bug is located. the goal is to have a resource that allows you to save all program state information. This is where the postmortem debugging technique comes in. including operating systems and native execution environments. the program can be restarted to avoid having too many users seeing these bugs and also to allow service to be up and running quickly. the debugger still has many positive qualities that I think people should consider when debugging programs. Using this method can be very beneficial because it allows programmers to fix bugs that are intermittent or root-caused in any stage of program development. [5] This type of debugging has been because although there may be a large amount of testing and debugging done prior to sending out a new piece of software. If you were to step over a function. step out. Breakpoints can be placed at specific line numbers. [5]” Since Gill’s description in 1951. After the state information is stored. in Visual Studio. allowing you to skip over working areas and focus on the areas that are actually causing the problems. When comparing the debugger to the print statement method. For example. This can be extremely helpful to see what is happening and why. 1 . this postmortem technology has been utilized in a variety of systems. but there may still be intermittent bugs that were not seen prior to the launch. iv. This allows you to see what your function is doing a line at a time. which can be very useful. The debugger allows you to step in. you can set a breakpoint at the beginning of a function and then step into this function to see what values are being stored in your variables.6 One of the main features of using the debugger is the ability to set breakpoints in your code. Although the print statement method is a preferred choice for a wide range of programmers. Stanley Gill described the post mortem technique by saying “the running program was modified to record important system state as it ran so that the programmer could later understand what happened and why the software failed. you can see that these techniques greatly. This can be beneficial if you are certain there is nothing wrong with this particular function and you just want to execute the code at the next breakpoint. The debugger’s interactive qualities allow you to choose what you want to see and where you want to start the execution of your code. there is a window that will tell you what a variable is when you are stepping into a function. I have used this many times and find this to be very helpful when trying to figure out what is going wrong. and at defined addresses [4]. An example of the Visual Studio debugger is shown below. For example. Using breakpoints allows you to control the flow of execution.

Unfortunately this information cannot be reachable from a global scope. Regardless of these pitfalls. the state information. Postmortem debugging can be extremely useful if you are required to debug complex software. Use in programs to find flaws. the software should not include any need for modifications that may impact performance of the software. Applys to hacking and engineering. Examples & Code -visual studio debugger -example print out Reverse engineering a technique of taking something and figuring out how it was made. or the ‘dump’ must be able to be transferred from one system to another for analysis purposes. the postmortem facility that is utilized should be permanently on without any need for additional add-ons to support the debugging process. Conclusion BACKGROUND Software engineering contains lots of high-level techniques for the entire design process.7 In order for postmortem debugging to be successful. Also. 1 . which is why this is a primary drawback. the save state information must include a stack trace so that program information can be observed in detail. Take a bridge and reverse engineer it to see how they made the structure. Allowing this to be used on multiple systems makes it much easier for computer scientists to locate the cause using an environment they are already familiar with to quickly find the problem [5]. Some of this state information can include function arguments on the call stack and also contexts related to future events [5]. the postmortem method has still been found to be effective because of the requirements described in the previously. or operating systems. enterprise systems. Finally. Unit Testing Techniques V. which results in important information being ignored. First. there is the possibility that the amount of memory needed could be larger than the entire heap. Also. the following areas must be satisfied. causing this technique to be unreliable in the event that we utilize more memory for serialization and code dumps [5]. The topic that had little attention CEN 4020 – Software Engineering: Essay No. This state information should provide enough information for developers to locate the root cause of the problem after seeing an error one time. Command line debugger for hacking purposes VI. but there are still some drawbacks associated with this technique. Additionally. v. One of the main disadvantages related to this method is the fact that the state information must be saved ahead of time. covering the full range from requirement analysis to post-delivery evolution.

8 is how to debug the code. An introduction section where you describe the problem domain and give a short description of prior approaches as far as you know.000 words that contains. Find publicly available code and/or demo programs related to debugging. A section on unit testing techniques. The essay should be less than 5. the subject line should contain the course prefix as well as the file name above. A section on general debugging methods. Once the research is done. 1 . “code testing”.e. in class. DELIVERABLES Using this file as a template. i. and how it can be further developed to assist the software engineer to mature into a high-profile code developer. OBJECTIVES The main objective of this active learning project is to systematically study the art and the daily practice of code debugging.g. etc. as a minimum.doc When submitting the file. FORMAT Use this MS Word file as the template and enter your text directly after the “E-mail” heading. Do a search on “code debugging techniques” and dig out all useful and understandable information. what types of techniques and/or tools are available to get rid of those unwanted computer pests. the following components: A short abstract of no more than 200 words. A section on examples and demos. write an essay of no more than 5.000 words or less than 10 pages. A list of keywords of no more than 5.doc. e. if any. A section on experiments. PROJECT DESCRIPTION This project consists of the following simple elements: Understand the concept of program design as presented in the book. digest all the information you gathered and write-up your experience with your independent research as described in the next section. “watchdogs”. Search for topics like “debugging”. You will study various programming practices to see how the skill of code debugging can be acquired. and perhaps in other classes you may have taken. not including illustrations and references. which describes the result of your independent research. if available or if you have done one or more yourself. Find methods and available systems for debugging. Proper illustrations throughout the text. John_Doe_1. Please name the file as follows: First name_Last name_Essay No. “fault-free coding”. Example: CEN 4020 – Software Engineering: Essay No.

1 . Please send the file to lpiegl@gmail. 2012.com no later than February 16.9 CEN_4020_John_Doe_1.doc SUBMISSION Your essay should be submitted electronically via e-mail attachment. (Please do not write below this line) Grade: Comments: CEN 4020 – Software Engineering: Essay No.

Sign up to vote on this title
UsefulNot useful