Solved

GDB and core files

Posted on 1997-05-11
8
1,527 Views
Last Modified: 2013-12-06
Sometimes when I compile programs so that I can debug the core file, I get a strange error message. For example, on a recent program of mine called orange, the command gdb orange core produced the following message:

Couldn't fetch registers from core file: file in wrong format.

Can anyone say what this means? Is there some esoteric switch I need to use with gdb?
0
Comment
Question by:ventnor
8 Comments
 
LVL 19

Expert Comment

by:xterm
Comment Utility
You can also start with both an executable program  and  a
       core file specified:

       gdb program core

(from the gdb man page) so the answer is no to the "esoteric
switch" - does Orange have debugging info compiled in?

0
 

Author Comment

by:ventnor
Comment Utility
Yes, I hope I'm not so stupid as to forget to compile debugging info in!!
0
 
LVL 1

Expert Comment

by:strobert
Comment Utility
do a file both on the core and your program the types should match (both a.out or both elf)... does your program change dirs? (thinking it might be dumping core other than where the executable is)
0
 

Author Comment

by:ventnor
Comment Utility
strobert: no, my program doesn't change directories. It's listed below (it's a simple buffer overflow program that I wrote for testing gdb; it's supposed to dump core).

include <syslog.h>
char buffer[4028];

   void main() {

   int i;
   for (i = 0; i<=6745; i++)
   buffer[i]='A';
   syslog(LOG_ERR, buffer);
               }

What I did then was compile the program using the -g switch:

gcc -g -o buff buff.c

I ran buff, and core was dumped. I then fired up gdb:

gdb buff core

And the message came up as above.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Expert Comment

by:strobert
Comment Utility
what gcc/gdb version?
I just tried the code on a Redhat 4.0 machine (gcc 2.7.2 gdb 4.16), and it works great
did you ever try doing a file buff and a file core?

0
 

Author Comment

by:ventnor
Comment Utility
strobert,

My version of gcc is 2.7, and my version of gdb is 4.15.1 When I do file core, I get the message "not in executable format: File format not recognised". When I do file buff, I get the prompt "Load new symbol table from "buff" y or n"

Hope this helps to throw light on the mystery....
0
 
LVL 1

Accepted Solution

by:
hcheng earned 50 total points
Comment Utility
Your gdb is too old.  You need gdb 4.16.  I had this error after I upgraded my gcc from 2.6.* to 2.7.*, but before my gdb was upgraded.

0
 

Author Comment

by:ventnor
Comment Utility
Thanks, I guessed something like that was the problem. The only reason I'm not awarding an "excellent" is that it would have been interesting to know why the older version of gdb doesn't work.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now