The function failing is attached. The #if 0 code if uncommented then leads to a
working version if retained throws a core dump.
Also if the following lines are anywhere added in the function once ( either
beginning / middle or end ) then the core is not dumped.
{FILE *fp=fopen("xdKm.txt","a+");
fprintf(fp,"%s \n","I am Here2");
fclose(fp);}
Regards,
Kiran
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Indika
Bandara Udagedara
Sent: Friday, July 18, 2008 12:47 PM
To: [email protected]
Subject: [c-prog] Re: Putting fprintf inside a function resolves a core dump ???
I too have had similar problems. they are usually because of stack
corruption/stack overflow. eg. writing off the bounds of a local char
buffer.
could u pls post the code.
--- In [email protected]<mailto:c-prog%40yahoogroups.com>, Kiran Divakaran
<[EMAIL PROTECTED]>
wrote:
>
> Hi All,
>
> I have a strange problem . One of the functions in the application
we use is dumping core.
>
> Once we put fprintf inside the function and traced through the file
, the core stops appearing . So the only change that was done to the
file was to
>
> put fprintfs inside it that to debug it and trace through the last
function which was appearing on the core stack.
>
> Apparently this is preventing the core from being dumped on SunOS.
>
> Also there are strange things like if the fprintf is commented /
added at particular points in the function then the core issue reappears.
>
> Is it got to do with the stack being in a inconsistent state and
calling a fprintf restores it unloads it in some way and things get
back to working.
>
> The stack should behave the way it is supposed to as a part of the
Operating system and would be the last thing to suspect it.
>
> But there have been issues like in the past where HP/SUN had genuine
bugs in their OS and later provided patches when raised with them.
>
> Is that the situation here or do we need to probe something on our
application front.
>
> Please let know your inputs on the same or rather explain this issue
technically as to what might be happening ?
>
>
> Regards,
> Kiran
>
>
>
>
> **************** CAUTION - Disclaimer *****************
> This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION
intended solely
> for the use of the addressee(s). If you are not the intended
recipient, please
> notify the sender by e-mail and delete the original message.
Further, you are not
> to copy, disclose, or distribute this e-mail or its contents to any
other person and
> any such actions are unlawful. This e-mail may contain viruses.
Infosys has taken
> every reasonable precaution to minimize this risk, but is not liable
for any damage
> you may sustain as a result of any virus in this e-mail. You should
carry out your
> own virus checks before opening the e-mail or attachment. Infosys
reserves the
> right to monitor and review the content of all messages sent to or
from this e-mail
> address. Messages sent to or from this e-mail address may be stored
on the
> Infosys e-mail system.
> ***INFOSYS******** End of Disclaimer ********INFOSYS***
>
>
> [Non-text portions of this message have been removed]
>
----------
int Xwl_RecvNxtMessage(OVERALL_PARAMx_PTR otPtr)
{
int ret = SUCCESS;
int iLength = 0;
{FILE *fp=fopen("xdKm.txt","a+");
fprintf(fp,"%s \n","I am Here1");
fclose(fp);}
if (((INETDM) || (INETRE)) && !Xwx_IsThisXopIdOfMenuForm(otPtr))
{
x_char sMsg[1024];
x_char * sCode;
/* log message and exit to menu */
Xwx_Log_GELMFError(otPtr);
/* otPtrulate message in Store */
x_sprintf(sMsg, "Script execution stopped because user input
was required on "
"%s.%s.%s.",
otPtr->CurrentFormPtr->SystemVariables.FormName,
otPtr->CurrentFormPtr->SystemVariables.BlockPtr->BlockKey.Name,
otPtr->CurrentFormPtr->SystemVariables.FieldPtr->FieldKey.Name);
if ((SUCCESS == get_hlM_commitflg()) || (SUCCESS ==
Xwx_GELMFQueueJob()))
{
sCode = "1007";
strcat(sMsg, " Script queued up for corrective
action.");
}
else
{
sCode = "0007";
}
Xwx_GELMFSetError(sCode, sMsg);
ret = Xwx_SendSuccessHeader(otPtr);
Xwx_SendGELMFStore(otPtr);
ret = Xwx_Send(otPtr);
return COMMIT_DONE;
}
if ((otPtr->inetPtr->inpMessageBuffer !=
otPtr->inetPtr->staticMessageBuffer) &&
(otPtr->inetPtr->inpMessageBuffer != NULL))
{
xlm_release(otPtr->inetPtr->inpMessageBuffer);
otPtr->inetPtr->inpMessageBuffer = NULL;
otPtr->inetPtr->extraBuffer = NULL;
}
{FILE *fp=fopen("xdKm.txt","a+");
fprintf(fp,"%s \n","I am Here2");
fclose(fp);}
otPtr->inetPtr->extraBuffer = (x_char *)0;
iLength = XT_DEF_INBUFF_SIZE;
ret = XTGetMsg(&(otPtr->pHandle), otPtr->inetPtr->staticMessageBuffer,
&iLength,
&otPtr->inetPtr->extraBuffer, XT_FALSE);
{FILE *fp=fopen("xdKm.txt","a+");
fprintf(fp,"%s \n","I am Here3");
fclose(fp);}
if (ret != XT_SUCCESS)
{
Xwx_Log(otPtr, "Nonblocking getMsg returned FAILURE.Quiting");
Xtl_SetErrorAndExit(otPtr, XT_NONBLOCK_RECV_FAILED);
}
{FILE *fp=fopen("xdKm.txt","a+");
fprintf(fp,"%s \n","I am Here4");
fclose(fp);}
otPtr->inetPtr->inpMessageBuffer =
otPtr->inetPtr->extraBuffer ?
otPtr->inetPtr->extraBuffer :
otPtr->inetPtr->staticMessageBuffer;
otPtr->inetPtr->inpMessageBuffer[iLength] = '\0';
{FILE *fp=fopen("xdKm.txt","a+");
fprintf(fp,"%s \n","I am Here5");
fclose(fp);}
if (xlb_XT_status & XT_STATUS_MESG_RECVD)
{
if (iLength == 0)
{
Xwx_Log(otPtr,"RecvNextMessage : iLength is 0");
/* Non block returned nothing */
if (!(xlb_XT_status & XT_STATUS_MSG_COLLECTED))
{
/* ie. nothing was accumulated since last
received */
x_char message[5];
x_sprintf(message, "%c%c%c%c",
XT_NORESPONSE, MESG_BODY_DELIM,
XT_NORESPONSE, MSG_DELIMITER);
ret = Xwx_SendSuccessHeader(otPtr);
Xwx_Log(otPtr, "Sending no response after
nonblocking recv.");
Xwx_CollectSend(otPtr,message);
}
ret = Xwx_Send(otPtr);
}
else
{
return SUCCESS;
}
{FILE *fp=fopen("xdKm.txt","a+");
fprintf(fp,"%s \n","I am at END");
fclose(fp);}
}
/* What to do ??? Do a direct receive.*/
/* get ready for the blocking call */
iLength = XT_DEF_INBUFF_SIZE;
otPtr->inetPtr->extraBuffer = NULL;
otPtr->inetPtr->staticMessageBuffer[0] = '\0';
Logger("Glue Layer : Going to call blocking recv\n");
{FILE *fp=fopen("xdKm.txt","a+");
fprintf(fp,"%s \n","I am Here 8 ");
fclose(fp);}
ret = XTGetMsg(&(otPtr->pHandle),
otPtr->inetPtr->staticMessageBuffer ,&iLength,
&otPtr->inetPtr->extraBuffer , XT_TRUE);
#if 0
{FILE *fp=fopen("xdKm.txt","a+");
fprintf(fp,"%s \n","I am Here 9 ");
fclose(fp);}
#endif
Logger("Glue Layer : Finished blocking recv.");
if (ret != XT_SUCCESS)
{
Xwx_Log(otPtr, "Blocking call failed.Time out.Clean and
exit...");
Xtl_SetErrorAndExit(otPtr, XT_BLOCK_RECV_FAILED);
}
{FILE *fp=fopen("xdKm.txt","a+");
fprintf(fp,"%s \n","I am Here 10 ");
fclose(fp);}
xlb_XT_status = glb_XT_status & ~(XT_STATUS_MESG_SENT);
xlb_XT_status = glb_XT_status | XT_STATUS_MESG_RECVD;
otPtr->inetPtr->inpMessageBuffer =
otPtr->inetPtr->extraBuffer ?
otPtr->inetPtr->extraBuffer :
otPtr->inetPtr->staticMessageBuffer;
otPtr->inetPtr->inpMessageBuffer[iLength] = '\0';
{FILE *fp=fopen("xdKm.txt","a+");
fprintf(fp,"%s \n","I am Here 11 ");
fclose(fp);}
return SUCCESS;
}
[Non-text portions of this message have been removed]