Getting to Know gdb
To run the program you are debugging, use the run command. This may be followed by any arguments you want to pass to the program, including the standard input and output specifiers < and >, and shell wildcards (*, ?, [, ]). You can't use C-shell history (!) or pipes (|).
For example, consider running the program exp through gdb. The following gdb command runs exp with the argument -b, taking the standard input to exp from invalues and redirecting standard output to the file outtable:
$ gdb exp (gdb) run -b < invalues > outtable
That is, this command runs exp -b < invalues > outtable. If you have not set any breakpoints or used any other gdb debugging features, exp will run until it terminates, either correctly or incorrectly.
If the program you're debugging terminates abnormally, control returns to gdb. You can then use gdb commands to find out why the program terminated. The backtrace command gives a stack backtrace showing exactly what the program was doing when it bombed out:
$ gdb badref (gdb) run Starting program: /home/los/mikel/cuser/badref 0x22c8 in march_to_infinity () at badref.c:16 16 h |= *p; (gdb) backtrace #0 0x22c8 in march_to_infinity () at badref.c:16 #1 0x2324 in setup () at badref.c:25 #2 0x2340 in main () at badref.c:30 (gdb)
backtrace (which is usually abbreviated back) produces a list of all active procedures and the arguments with which they were called, starting with the most recent. So this display shows that the program died in a function named march_to_infinity(); this function was called by the function setup(), which in turn was called by the function main(). The only thing left is to figure out exactly what wrong in march_to_infinity().
You can inspect the variable values by using the print command. Let's use it to see exactly what happened in the previous program. First, we'll list some code to see what we're dealing with:
(gdb) list
8
9 p=&j;
10 /* march off the end of the world*/
11 for ( i = 0; i < VERYBIG; i++)
12 {
13 h |= *p;
14 p++;
15 }
16 printf("h: %d\en",h);
17
It should already be pretty clear what's happening. p is some kind of a pointer; we can test that by using the whatis command, which shows us its declaration:
(gdb) whatis p type = int * (gdb) print p $1 = (int *) 0xf8000000 (gdb) print *p $2 = Cannot access memory at address 0xf8000000. (gdb) print h $3 = -1 (gdb)
When we look at p, we see that it's pointing somewhere up in the stratosphere. Of course, there's no ad hoc way to know whether this value for p is legitimate or not. But we can see if we can read the the data p points to, just as our program did—and when we give the command print *p, we see that it's pointing to inaccessible data.
print is one of gdb's true power features. You can use it to print the value of any expression that's valid in the language you're debugging. In additions to variables from your program, expressions may include:
Calls to functions within your program; these function calls may have “side-effects” (i.e., they can do things like modify global variables that will be visible when you continue program execution).
(gdb) print find_entry(1.0) $1 = 3Data structures and other complex objects.
(gdb) print *table_start $8 = {e_reference = '\e000' <repeats 79 times>, location = 0x0, next = 0x0}
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
- RSS Feeds
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- Validate an E-Mail Address with PHP, the Right Way
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Download the Free Red Hat White Paper "Using an Open Source Framework to Catch the Bad Guy"
- A Topic for Discussion - Open Source Feature-Richness?
- Dynamic DNS—an Object Lesson in Problem Solving
- Tech Tip: Really Simple HTTP Server with Python




2 hours 2 min ago
4 hours 18 min ago
4 hours 46 min ago
5 hours 44 min ago
7 hours 13 min ago
8 hours 22 min ago
9 hours 8 min ago
15 hours 44 min ago
21 hours 22 min ago
1 day 3 hours ago