public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: Regarding gcc debugging
@ 2003-09-16 19:21 lrtaylor
  0 siblings, 0 replies; 4+ messages in thread
From: lrtaylor @ 2003-09-16 19:21 UTC (permalink / raw)
  To: girdhar_puneet, gcc-help

Could it be because Sm_UnInit is getting called twice: once in your main routine by you, and then again in the object's destructor?  If Sm_UnInit is doing some cleanup work, and then tries to do it again, the structures it is trying to clean up the second time would not longer be valid, and could cause a core dump.  It seems to me that if you are calling in it the destructor, you probably shouldn't also be calling it directly in your "main" routine.  (That said, you'll know the API that you're working with - this is just a thought...)

Thanks,
Lyle Taylor

-----Original Message-----
From: puneet girdhar [mailto:girdhar_puneet@yahoo.com]
Sent: Tuesday, September 16, 2003 12:45 PM
To: gcc-help@gcc.gnu.org
Subject: Regarding gcc debugging

Hi,
I am trying to debug a C++ program with gdb on Linux
AS 2.1. when the program terminates,the destructor is
called and this destructor in turn calls the
un-initializer routine.After the Un-inilization
routine is over it does not give core dump.But then it
goes in main and gives core dump.

      ***************source code starts***********

void SmAgentExample::Sm_UnInit( )
{
    int iResult;

    printf("Value of pSmApiHandle inside Sm_UnInit is
%x\n",pSmApiHandle);

    if ( NULL != pSmApiHandle ) {

        Sm_Logout();
        //
        // UnInitialize the Agent API
        //
        // Return values:
        //      SM_AGENTAPI_SUCCESS
        //      SM_AGENTAPI_FAILURE
        //      SM_AGENTAPI_NOCONNECTION
        iResult = Sm_AgentApi_UnInit( &pSmApiHandle );
        if (SM_AGENTAPI_SUCCESS==iResult)
            printf (  "Agent Released\n" );
        else if (SM_AGENTAPI_FAILURE==iResult)
            printf ( "UnInitialzation Failed\n" );
        else if (SM_AGENTAPI_NOCONNECTION==iResult)
            printf ( "Timeout for server response!\n"
);
    }
        printf("I am here\n");
    login = 0;
}

SmAgentExample::~SmAgentExample()
{

    pSmApiHandle = NULL;
    printf("Inside destructor\n");
    Sm_AgentApi_FreeAttributes(iNumAttributes,
pAttributes);
    printf("Before Sm_UnInit function\n");
    Sm_UnInit( );
}

int main()
{
   .....
   .....
   while{
   switch(input)
   case 'q' :
          break;
  .......
   }
   a.Sm_UnInit( );
   printf ( "Done, thank you for Testing the API.\n"
);
   return 0;
}
     **************source code ends***********

     -------------output of gdb---------

FTP> q
Breakpoint 1, SmAgentExample::Sm_UnInit() (this=0x1)
at smagentexample.cpp:220
220     {
(gdb) s
0x0804a601 in main ()
(gdb) s
Single stepping until exit from function main,
which has no line number information.
Value of pSmApiHandle inside Sm_UnInit is 8052728
Agent Released
I am here
Done, thank you for Testing the API.
Inside destructor
Before Sm_UnInit function

Breakpoint 1, SmAgentExample::Sm_UnInit()
(this=0xbffe5a50) at smagentexample.cpp:220
220     {
(gdb) s
0x0804a601 in main ()
(gdb) s
Single stepping until exit from function main,
which has no line number information.
Value of pSmApiHandle inside Sm_UnInit is 0
I am here

Breakpoint 3, main () at smagentexample.cpp:778
778     }
(gdb) s
0x4021a727 in __libc_start_main () from /lib/libc.so.6
(gdb) s
Single stepping until exit from function
__libc_start_main,
which has no line number information.

Program received signal SIGSEGV, Segmentation fault.
0x403c7112 in ?? (). When i gave bt command it gave:

(gdb) bt
#0  0x403c7112 in ?? ()
#1  0x4021a730 in __libc_start_main () from
/lib/libc.so.6

-------------output of gdb---------------------

Can anybody give any ptrs on this that why it is
dumping core. Thanks in advance.

Regards
Puneet


________________________________________________________________________
Yahoo! India Matrimony: Find your partner online.
Go to http://yahoo.shaadi.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Regarding gcc debugging
  2003-09-16 18:45 puneet girdhar
@ 2003-09-17  2:01 ` Burak Serdar
  0 siblings, 0 replies; 4+ messages in thread
From: Burak Serdar @ 2003-09-17  2:01 UTC (permalink / raw)
  To: puneet girdhar; +Cc: gcc-help

You probably have a corrupt heap, as the sigsegv arrives after main 
returned, the destructor is called, and apparently, after that 
destructor is returned. The reason is probably in some other place in 
your code.

puneet girdhar wrote:
> Hi,
> I am trying to debug a C++ program with gdb on Linux
> AS 2.1. when the program terminates,the destructor is
> called and this destructor in turn calls the
> un-initializer routine.After the Un-inilization
> routine is over it does not give core dump.But then it
> goes in main and gives core dump.
> 
>       ***************source code starts***********
> 
> void SmAgentExample::Sm_UnInit( )
> {
>     int iResult;
> 
>     printf("Value of pSmApiHandle inside Sm_UnInit is
> %x\n",pSmApiHandle);
> 
>     if ( NULL != pSmApiHandle ) {
> 
>         Sm_Logout();
>         //
>         // UnInitialize the Agent API
>         //
>         // Return values:
>         //      SM_AGENTAPI_SUCCESS
>         //      SM_AGENTAPI_FAILURE
>         //      SM_AGENTAPI_NOCONNECTION
>         iResult = Sm_AgentApi_UnInit( &pSmApiHandle );
>         if (SM_AGENTAPI_SUCCESS==iResult)
>             printf (  "Agent Released\n" );
>         else if (SM_AGENTAPI_FAILURE==iResult)
>             printf ( "UnInitialzation Failed\n" );
>         else if (SM_AGENTAPI_NOCONNECTION==iResult)
>             printf ( "Timeout for server response!\n"
> );
>     }
>         printf("I am here\n");
>     login = 0;
> }
> 
> SmAgentExample::~SmAgentExample()
> {
> 
>     pSmApiHandle = NULL;
>     printf("Inside destructor\n");
>     Sm_AgentApi_FreeAttributes(iNumAttributes,
> pAttributes);
>     printf("Before Sm_UnInit function\n");
>     Sm_UnInit( );
> }
> 
> int main()
> {
>    .....
>    .....
>    while{
>    switch(input)
>    case 'q' :
>           break;
>   .......
>    }
>    a.Sm_UnInit( );
>    printf ( "Done, thank you for Testing the API.\n"
> );
>    return 0;
> }
>      **************source code ends***********
> 
>      -------------output of gdb---------
> 
> FTP> q
> Breakpoint 1, SmAgentExample::Sm_UnInit() (this=0x1)
> at smagentexample.cpp:220
> 220     {
> (gdb) s
> 0x0804a601 in main ()
> (gdb) s
> Single stepping until exit from function main, 
> which has no line number information.
> Value of pSmApiHandle inside Sm_UnInit is 8052728
> Agent Released
> I am here
> Done, thank you for Testing the API.
> Inside destructor
> Before Sm_UnInit function
> 
> Breakpoint 1, SmAgentExample::Sm_UnInit()
> (this=0xbffe5a50) at smagentexample.cpp:220
> 220     {
> (gdb) s
> 0x0804a601 in main ()
> (gdb) s
> Single stepping until exit from function main, 
> which has no line number information.
> Value of pSmApiHandle inside Sm_UnInit is 0
> I am here
> 
> Breakpoint 3, main () at smagentexample.cpp:778
> 778     }
> (gdb) s
> 0x4021a727 in __libc_start_main () from /lib/libc.so.6
> (gdb) s
> Single stepping until exit from function
> __libc_start_main, 
> which has no line number information.
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x403c7112 in ?? (). When i gave bt command it gave:
> 
> (gdb) bt
> #0  0x403c7112 in ?? ()
> #1  0x4021a730 in __libc_start_main () from
> /lib/libc.so.6
> 
> -------------output of gdb---------------------
> 
> Can anybody give any ptrs on this that why it is
> dumping core. Thanks in advance.
> 
> Regards
> Puneet
> 
> 
> ________________________________________________________________________
> Yahoo! India Matrimony: Find your partner online.
> Go to http://yahoo.shaadi.com
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Regarding gcc debugging
@ 2003-09-16 18:45 puneet girdhar
  2003-09-17  2:01 ` Burak Serdar
  0 siblings, 1 reply; 4+ messages in thread
From: puneet girdhar @ 2003-09-16 18:45 UTC (permalink / raw)
  To: gcc-help

Hi,
I am trying to debug a C++ program with gdb on Linux
AS 2.1. when the program terminates,the destructor is
called and this destructor in turn calls the
un-initializer routine.After the Un-inilization
routine is over it does not give core dump.But then it
goes in main and gives core dump.

      ***************source code starts***********

void SmAgentExample::Sm_UnInit( )
{
    int iResult;

    printf("Value of pSmApiHandle inside Sm_UnInit is
%x\n",pSmApiHandle);

    if ( NULL != pSmApiHandle ) {

        Sm_Logout();
        //
        // UnInitialize the Agent API
        //
        // Return values:
        //      SM_AGENTAPI_SUCCESS
        //      SM_AGENTAPI_FAILURE
        //      SM_AGENTAPI_NOCONNECTION
        iResult = Sm_AgentApi_UnInit( &pSmApiHandle );
        if (SM_AGENTAPI_SUCCESS==iResult)
            printf (  "Agent Released\n" );
        else if (SM_AGENTAPI_FAILURE==iResult)
            printf ( "UnInitialzation Failed\n" );
        else if (SM_AGENTAPI_NOCONNECTION==iResult)
            printf ( "Timeout for server response!\n"
);
    }
        printf("I am here\n");
    login = 0;
}

SmAgentExample::~SmAgentExample()
{

    pSmApiHandle = NULL;
    printf("Inside destructor\n");
    Sm_AgentApi_FreeAttributes(iNumAttributes,
pAttributes);
    printf("Before Sm_UnInit function\n");
    Sm_UnInit( );
}

int main()
{
   .....
   .....
   while{
   switch(input)
   case 'q' :
          break;
  .......
   }
   a.Sm_UnInit( );
   printf ( "Done, thank you for Testing the API.\n"
);
   return 0;
}
     **************source code ends***********

     -------------output of gdb---------

FTP> q
Breakpoint 1, SmAgentExample::Sm_UnInit() (this=0x1)
at smagentexample.cpp:220
220     {
(gdb) s
0x0804a601 in main ()
(gdb) s
Single stepping until exit from function main, 
which has no line number information.
Value of pSmApiHandle inside Sm_UnInit is 8052728
Agent Released
I am here
Done, thank you for Testing the API.
Inside destructor
Before Sm_UnInit function

Breakpoint 1, SmAgentExample::Sm_UnInit()
(this=0xbffe5a50) at smagentexample.cpp:220
220     {
(gdb) s
0x0804a601 in main ()
(gdb) s
Single stepping until exit from function main, 
which has no line number information.
Value of pSmApiHandle inside Sm_UnInit is 0
I am here

Breakpoint 3, main () at smagentexample.cpp:778
778     }
(gdb) s
0x4021a727 in __libc_start_main () from /lib/libc.so.6
(gdb) s
Single stepping until exit from function
__libc_start_main, 
which has no line number information.

Program received signal SIGSEGV, Segmentation fault.
0x403c7112 in ?? (). When i gave bt command it gave:

(gdb) bt
#0  0x403c7112 in ?? ()
#1  0x4021a730 in __libc_start_main () from
/lib/libc.so.6

-------------output of gdb---------------------

Can anybody give any ptrs on this that why it is
dumping core. Thanks in advance.

Regards
Puneet


________________________________________________________________________
Yahoo! India Matrimony: Find your partner online.
Go to http://yahoo.shaadi.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Regarding gcc debugging
@ 2003-09-16 18:01 puneet girdhar
  0 siblings, 0 replies; 4+ messages in thread
From: puneet girdhar @ 2003-09-16 18:01 UTC (permalink / raw)
  To: gcc-help

 
 

________________________________________________________________________
Yahoo! India Matrimony: Find your partner online.
Go to http://yahoo.shaadi.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-09-17  2:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-16 19:21 Regarding gcc debugging lrtaylor
  -- strict thread matches above, loose matches on Subject: below --
2003-09-16 18:45 puneet girdhar
2003-09-17  2:01 ` Burak Serdar
2003-09-16 18:01 puneet girdhar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).