473,888 Members | 2,194 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

debugging a seg fault

I understand there's socket / recursive calls here, but this is a C
question, really it is:

Here's the code block in question:

#if defined(__GLIBC __)
{
struct hostent hent;
char hbf[8192];
memset(&hbf, '\0', 8192);
/* for systems using GNU libc */
if((gethostbyna me_r(hostparam, &hent, hbf, sizeof(hbf), &hp,
&herrno) < 0)){
hp = NULL;
}
}
#elif defined(sun)

I'm passing Bad Things to gethostbyname_r and I'm trying to get to the
bottom of the problem. Here's my debugging session:

Breakpoint 1, new_socket (C=0xb7518b90, hostparam=0xb75 0efe4
"lsnas009.lsn.j oedog.org", portparam=80) at sock.c:121
121 memset(&hbf, '\0', 8192);
(gdb) print hbf
$2 = '\0' <repeats 7976 times>, "ØÐN", '\0' <repeats 161 times>,
"Ta8", '\0' <repeats 13 times>, "üÆB\000¸:I\000 u\2008\000]oH
\000\000\020\00 0\000¸:I\000TZ\ 000\000\000\000 \000\000¸:I"
(gdb) print hent
$3 = {h_name = 0x19e0990 "&", h_aliases = 0x0, h_addrtype = 27133736,
h_length = 4135971, h_addr_list = 0x486f6a}
[Editor's note: WTF??? h_name is "&"]
(gdb) n

Lifting the server siege...123 if((gethostbyna me_r(hostparam,
&hent, hbf, sizeof(hbf), &hp, &herrno) < 0)){
(gdb) n

Program received signal SIG32, Real-time event 32.
0x0042cfae in __open_nocancel () from /lib/tls/libc.so.6

I'm butchering something, somewhere and I'm having trouble getting to
the bottom of it. Any thoughts? How do I debug this?

Cheers,
Jeff
Jul 24 '08 #1
6 2266
Jeff wrote:
I understand there's socket / recursive calls here, but this is a C
question, really it is:
Actually, it looks more like a gdb question. I'll offer a few
ideas anyhow, but realize that I'm not a gdb expert.
Here's the code block in question:

#if defined(__GLIBC __)
{
struct hostent hent;
char hbf[8192];
memset(&hbf, '\0', 8192);
Not really a problem, but this should be memset(hbf, '\0', 8192),
or better memset(hbf, '\0', sizeof hbf). Even better still would be
to find out whether you actually need to zero hbf[] before using it;
the clearing might be unnecessary.
/* for systems using GNU libc */
if((gethostbyna me_r(hostparam, &hent, hbf, sizeof(hbf), &hp,
&herrno) < 0)){
This has more arguments than the gethostbyname_r () that I know,
but since gethostbyname_r () isn't a Standard C function there may
well be system-by-system variation. You didn't show what hp and
herrno are, but I'll just assume they make some kind of sense.
hp = NULL;
}
}
#elif defined(sun)

I'm passing Bad Things to gethostbyname_r and I'm trying to get to the
bottom of the problem. Here's my debugging session:

Breakpoint 1, new_socket (C=0xb7518b90, hostparam=0xb75 0efe4
"lsnas009.lsn.j oedog.org", portparam=80) at sock.c:121
121 memset(&hbf, '\0', 8192);
(gdb) print hbf
$2 = '\0' <repeats 7976 times>, "ØÐN", '\0' <repeats 161 times>,
"Ta8", '\0' <repeats 13 times>, "üÆB\000¸:I\000 u\2008\000]oH
\000\000\020\00 0\000¸:I\000TZ\ 000\000\000\000 \000\000¸:I"
Here we get into gdb-specific territory. If I'm not mistaken,
the breakpoint stops the program *before* executing the line that's
printed out, so you're printing hbf *before* clearing it, and all
you're seeing is the garbage it contains at its creation.
(gdb) print hent
$3 = {h_name = 0x19e0990 "&", h_aliases = 0x0, h_addrtype = 27133736,
h_length = 4135971, h_addr_list = 0x486f6a}
[Editor's note: WTF??? h_name is "&"]
Similarly with hent: If you examine the contents of an object
that hasn't been initialized, so you can expect nothing sensible.
(gdb) n

Lifting the server siege...123 if((gethostbyna me_r(hostparam,
&hent, hbf, sizeof(hbf), &hp, &herrno) < 0)){
I have no idea at all where that "Lifting the server siege..."
came from. Is this a multi-threaded program? If so, maybe one of
those other threads is running amok and trampling memory with heavy
mud-caked boots. (Multi-threading is not covered by the C language
standard, so the behavior of multi-threaded programs is another of
those things that varies from system to system.)
(gdb) n

Program received signal SIG32, Real-time event 32.
0x0042cfae in __open_nocancel () from /lib/tls/libc.so.6

I'm butchering something, somewhere and I'm having trouble getting to
the bottom of it. Any thoughts? How do I debug this?
First, check that the calls to system-specific routines like
gethostbyname_r () are in fact written correctly: Making sure that
all the appropriate header files have been #include'd is a good start.
Second, check that you're using gdb correctly; if you need help on
that, a Gnu forum is the place to seek it. Third, Gnu forums are
also likely to be the best sources of information about glibc details;
comp.unix.progr ammer is another place to get advice on Unix networking
API's. Finally, try comp.programmin g.threads if you need ideas about
debugging multi-threaded programs.

... and if you ever *do* have a C question, please come back
here for advice, help, and unending flames.

--
Er*********@sun .com
Jul 24 '08 #2
David Resnick <ln********@gma il.comwrites:
[...]
If your questions have to do with threading/gethostbyname_r
themselves, you're better off asking in comp.programmer .unix.
[...]

Or comp.unix.progr ammer, which has the virtue of actually existing.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 24 '08 #3
Jeff wrote:
>
I understand there's socket / recursive calls here, but this is
a C question, really it is:

Here's the code block in question:

#if defined(__GLIBC __)
{
To start with, you are using a reserved identifier. All
identifiers with two leading '_' chars are reserved for the
implementation.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
Jul 25 '08 #4
CBFalconer <cb********@yah oo.comwrote:
Jeff wrote:

I understand there's socket / recursive calls here, but this is
a C question, really it is:

Here's the code block in question:

#if defined(__GLIBC __)
{
To start with, you are using a reserved identifier. All
identifiers with two leading '_' chars are reserved for the
implementation.
He's testing something ("__GLIBC__" ) that might be defined by the
implementation, so what's the worry? It's not the OP defining it.

Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\______________ ____________ http://toerring.de
Jul 25 '08 #5
On Jul 24, 4:18 pm, Eric Sosman <Eric.Sos...@su n.comwrote:
Jeff wrote:
I understand there's socket / recursive calls here, but this is a C
question, really it is:

Actually, it looks more like a gdb question. I'll offer a few
ideas anyhow, but realize that I'm not a gdb expert.
Thanks. I thought I was looking at it *after* initialization. Electric
Fence offered no additional insight. I'll try David's suggestion and
use valgrind. I'm reasonably certain I'm clobbering something prior to
the gethostbyname_r call. This code fails only in conjunction with a
new authentication mechanism I added.

Jeff
Jul 25 '08 #6
Jeff <jo******@gmail .comwrites:
On Jul 24, 4:18 pm, Eric Sosman <Eric.Sos...@su n.comwrote:
>Jeff wrote:
I understand there's socket / recursive calls here, but this is a C
question, really it is:

Actually, it looks more like a gdb question. I'll offer a few
ideas anyhow, but realize that I'm not a gdb expert.

Thanks. I thought I was looking at it *after* initialization. Electric
Fence offered no additional insight. I'll try David's suggestion and
use valgrind. I'm reasonably certain I'm clobbering something prior to
the gethostbyname_r call. This code fails only in conjunction with a
new authentication mechanism I added.

Jeff
Be aware you can use gdb to set read and write break points too.

http://www.unknownroad.com/rtfm/gdbtut/gdbwatch.html
Jul 25 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
31945
by: Maksim Kasimov | last post by:
Hello, my programm sometime gives "Segmentation fault" message (no matter how long the programm had run (1 day or 2 weeks). And there is nothing in log-files that can points the problem. My question is how it possible to find out where is the problem in the code? Thanks for any help. Python 2.2.3 FreeBSD -- Best regards,
13
22190
by: N.S. du Toit | last post by:
Just having a bit of trouble programming with C under FreeBSD 5.1 using the gcc compiler. I'm a bit new to C so my apologies if the answer to my question appear obvious :) Basically I've written a function that will check whether a string is an ip address (see the function isIP below). During my attempt at debugging this problem I inserted a printf statement before the return command from the statement, and also a printf statement...
9
2029
by: Narendran Kumaraguru Nathan | last post by:
Hi all, I am fairly experianced in C. I am writing a program in which I'm getting a segmentation fault. The problem is that it is getting the segmentation fault when executing calloc. I tried debugging it, with no use. I tried to figure out the common reasons (1) Using a memory location which is not allocated. (2) Using memory which is freed. (3) Function use before declaration. I didn't use any other debuggers or tools other than ddd. My...
5
3003
by: Fra-it | last post by:
Hi everybody, I'm trying to make the following code running properly, but I can't get rid of the "SEGMENTATION FAULT" error message when executing. Reading some messages posted earlier, I understood that a segmentation fault can occur whenever I declare a pointer and I leave it un-initialized. So I thought the problem here is with the (const char *)s in the stuct flightData (please note that I get the same fault declaring as char * the...
0
1930
by: jgarber | last post by:
Hello, I just upgraded MySQLdb to the 1.2.0 version provided by Redhat Enterprise Linux ES4. At that point I began to get segfaults when importing twisted after MySQLdb, but not before. -- RedHat Enterprise Linux ES 4 (fully updated) Python 2.3.4 mysql-python (MySQLdb) version 1.2.0
7
5886
by: pycraze | last post by:
I would like to ask a question. How do one handle the exception due to Segmentation fault due to Python ? Our bit operations and arithmetic manipulations are written in C and to some of our testcases we experiance Segmentation fault from the python libraries. If i know how to handle the exception for Segmentation fault , it will help me complete the run on any testcase , even if i experiance Seg Fault due to any one or many functions in...
1
5378
by: kumarangopi | last post by:
two.c: #include<stdio.h> main() { printf("hello C is working"); } #gcc -0 two two.c #./two segmetnation fault
2
3711
by: Zach | last post by:
I compiled a game client and it crashed (segmentation fault) resulting in a core file being generated. I'm trying to find out exactly what caused it to crash. Any ideas how I can do this with gdb? In the Makefile can I just add a "-g" flag to have the binary produced with debugging symbols? The source is written in ANSI C. This is what I have now: "CC = gcc" The client binary is 433680 and the core file produced when it crashed
85
3122
by: Bill Cunningham | last post by:
I have put together this program that seems to do what I want without error checking added yet. If I just run the program it produces a segmentation fault. If I add the proper value say 43.56 it's fine. Does anyone see what's wrong ? I have a c99 compiler. Thanks. #include <stdio.h> #include <stdlib.h> int main ( int argc, char *argv ) { FILE*fp;
4
3034
by: jemccarthy13 | last post by:
I am a very very low level beginner programmer, trying to teach myself C, and I could use some help with the following program for guessing a random number. Please, when helping, try to use low level functions and such. A Segmentation Fault occurs sometime between the running of lines 30-40 while debugging. #include <stdio.h>
0
9799
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11173
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10772
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9593
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7988
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5810
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6011
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4239
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.