www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/10/11/06:48:46

Xref: news-dnh.mv.net comp.os.msdos.djgpp:2552
Path: news-dnh.mv.net!mv!news.sprintlink.net!jaring.my!alpha.seccom.com.my!news.uoregon.edu!waikato!not-for-mail
From: jpg AT cs DOT waikato DOT ac DOT nz (J P Griffiths)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Using GDB
Date: 10 Oct 1995 21:40:27 GMT
Organization: The University of Waikato
Lines: 43
Sender: jpg AT waikato DOT ac DOT nz
References: <DG48AG DOT CHI AT jade DOT mv DOT net>
Reply-To: jpg AT waikato DOT ac DOT nz
Nntp-Posting-Host: lucy.cs.waikato.ac.nz
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Dj-Gateway: from newsgroup comp.os.msdos.djgpp

IncanTationS (thanatos AT axs DOT net) wrote:
: I have a program that compiles with no errors, but when I run it, it 
: Segfaults almost immeadiantly...although I am using gcc rather than djgpp...
: I was wondeing how I can use GDB to trace down where in the code it was 
: segfaulting at...

compile all code with the -g flag and optimisations *off*.

If you are debugging on a *nix platform then just type "gdb a.out" (or 
wahtever the binary is called.  Using v2 djgpp you use "gdb a.out" where
a.out is the unstubbed binary (not the .exe file).

Once gdb boots up,  you are ready to go.  If you just want to find where 
the program exits,  type "r <enter>". This will run the program,  and 
when it exits,  will tell you what signals (if any) caused it to finish,
and the line number and source file where It crashed.

If you want to examine the routine that caused the program to crash,
you can use "b some_function <enter>" to set a breakpoint at a given 
function. Your program will pause at the start of the function once you 
type "r <enter>".
  
Use "l <enter>" to list the current source lines.  you can also use
"p var_name <enter>" to print the contents of a variable in scope.
Complex structures and variables can also be printed,  such as
"p *some_ptr_ptr->somefield[someindex]",  and "p some_funct(someval)".

you can also set automatic display of variables using "display somevar",
single step source lines with "n <enter>",  skip lines with "s <enter>",
and quit with "q <enter>".

Try "help <enter>" within gdb for more infrmation,  and read the gdb 
documentation in the online info browser that comes with gcc.

If you have any more qtns about non-djgpp related c or unix enquiries,
try the *.unix.* groups which will be more suited to those questions,
with people more likely to respond favourably with good information.

Thanks for your cooperation,  and I hope the above is of some help.

Cheers,
   Jon.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019