You are not logged in.

#1 2013-12-16 21:38:59

Slippery_John
Member
Registered: 2013-06-19
Posts: 3

GDB isn't breaking

I wanted to be able to do some work on my desktop since it's more comfortable than my laptop, but I have come across a frustrating error: gdb refuses to break on anything. The programs just run merrily along. I've even tried setting breakpoints at EVERY SINGLE LINE and still nothing.

I honestly haven't got a single clue where to even start looking for a solution. I would normally assume something in code, but my laptop will run the same exact code and have gdb work just fine. I also haven't performed any sort of configurations on gdb in either machine.

Anybody have any idea where I might begin to look?

Offline

#2 2013-12-16 21:51:36

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 12,749

Re: GDB isn't breaking

Right out of the gate, I would guess you missed the -g flag when you compiled your target. 
Are you using autotools to compile?

You say the targets are the exact same code.  Are they?  Any chance the one that works is actually a bit larger?


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Like you, I have no idea what you are doing, but I am pretty sure it is wrong...Jasonwryan
----
How to Ask Questions the Smart Way

Offline

#3 2013-12-16 22:49:30

Allan
Developer
From: Brisbane, AU
Registered: 2007-06-09
Posts: 10,399
Website

Offline

#4 2013-12-18 13:32:53

Slippery_John
Member
Registered: 2013-06-19
Posts: 3

Re: GDB isn't breaking

ewaller wrote:

Right out of the gate, I would guess you missed the -g flag when you compiled your target. 
Are you using autotools to compile?

You say the targets are the exact same code.  Are they?  Any chance the one that works is actually a bit larger?

I use a makefile to compile both, and I include the -g flag in that. I'll check tonight to see if the output files are significantly different. I'll also give the other suggestion a shot. For now, here's a sample I'm trying out that produces the error:

Makefile:

CC = gcc
CFLAGS = -Wall -c -g
LDFLAGS = -g

PROG = test


$(PROG): gdbexample.o author.o
	$(CC) gdbexample.o author.o -o $(PROG) $(LDFLAGS)

gdbexample.o: gdbexample.c author.h
	$(CC) gdbexample.c $(CFLAGS)

author.o: author.c author.h
	$(CC) author.c $(CFLAGS)

clean: 
	rm -f *.o test *~

author.c:

#include <stdio.h>
#include"author.h"

void display_author_details(Author person){  
  int i;
  printf("Author's name: %s\n", person.name);
  printf("Number of published books: %d \n", person.book_count);
  for (i=0; i<person.book_count; i++) {
    printf("%d. %s\n", i+1, person.book_name[i]);
  }
}

author.h:

typedef struct {
  char name[30];
  int book_count;
  char book_name[5][70]; /* 5 books, 70 character names */
} Author;

void display_author_details(Author guy);

gdbexample.c:

/* Name: gdbexample.c 
 * Author: Archana Chidanandan, December 3, 2007
 * Modified:  Delvin Defoe on March 11, 2008
 * Description: This program is meant to be used with a tutorial on 
 * GDB. 
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "author.h"

int main(int argc, char *argv[]) {
  
  int i;
  
  /* Used to show how pointers and their pointees
     can be examined using GDB */
  Author *ptr;       
  
  /* Used to show how a struct can be examined 
     using GDB */
  Author one;        
  
  /* The following is included to show how command line arguments must
     be specified when running the program in GDB */
  if (argc<2){
    printf("Error: incorrect number of arguments\n");
    printf("Enter <exec_name> <num_of_times_to_display_details>\n");
    exit(1);
  }
  
  int count = atoi(argv[1]);
  
  strcpy(one.name,"J. K. Rowling");
  one.book_count = 3;
  strcpy(one.book_name[0],"Harry Potter and the Philosopher's Stone");
  strcpy(one.book_name[1],"Harry Potter and the Chamber of Secrets");
  strcpy(one.book_name[2],"Harry Potter and the Prisoner of Azkaban");
  
  ptr = &one;

  for (i=0; i<count; i++) {
    /* Function defined in author.c.
       Use to demonstrate:
       a. "step"
       b. Setting a breakpoint in another file
    */
    display_author_details(one);  
  }

  return 0;
}

And I run the following commands:

$ gdb ./test
(gdb) b main
(gdb) run 2

Offline

Board footer

Powered by FluxBB