473,498 Members | 1,833 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((gethostbyname_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=0xb750efe4
"lsnas009.lsn.joedog.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\000u\2008\000]oH
\000\000\020\000\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((gethostbyname_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 2239
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((gethostbyname_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=0xb750efe4
"lsnas009.lsn.joedog.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\000u\2008\000]oH
\000\000\020\000\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((gethostbyname_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.programmer is another place to get advice on Unix networking
API's. Finally, try comp.programming.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********@gmail.comwrites:
[...]
If your questions have to do with threading/gethostbyname_r
themselves, you're better off asking in comp.programmer.unix.
[...]

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

--
Keith Thompson (The_Other_Keith) 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********@yahoo.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...@sun.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...@sun.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
31898
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...
13
22144
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...
9
2008
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...
5
2974
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...
0
1908
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. --...
7
5856
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...
1
5354
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
3678
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?...
85
2980
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...
4
3012
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...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7004
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...
0
7167
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,...
0
5464
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,...
1
4915
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...
0
3095
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...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.