Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Print call stack in Mainframe C

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> ABENDS & Debugging
View previous topic :: :: View next topic  
Author Message
DIPANKAR SAHA

New User


Joined: 15 Mar 2018
Posts: 1
Location: India

PostPosted: Thu Mar 15, 2018 2:58 pm    Post subject: Print call stack in Mainframe C
Reply with quote

My C program is failing because of memory abend. Can i print the call stack at the time of failure like which function asked the memory that cause the fail ?
Back to top
View user's profile Send private message

prino

Senior Member


Joined: 07 Feb 2009
Posts: 1121
Location: Vilnius, Lithuania

PostPosted: Thu Mar 15, 2018 4:16 pm    Post subject:
Reply with quote

Since when can memory abend? You're on a forum for experts, tell us what really happened and don't invent fake descriptions!
Back to top
View user's profile Send private message
enrico-sorichetti

Senior Member


Joined: 14 Mar 2007
Posts: 10543
Location: italy

PostPosted: Thu Mar 15, 2018 6:53 pm    Post subject: Reply to: Print call stack in Mainframe C
Reply with quote

if instead of a generic whining You had posted the messages received
it would have been easier for us to answer.

a C program abending on a malloc/free is a badly written program ...
a malloc returns the address of the malloced storage/memory
after a malloc the program should check for a not NULL value
and behave accordingly
before issuing a free a well behaved program should check for a non NULL storage/memory pointer

here is a snippet to show what I am talking about

Code:

#include <inttypes.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

int main()
{
    uint8_t *area ;
    int      areasize = 16*1024*1024 ;

    uint8_t *null ;

    printf( "***** start of test *****\n");

    printf( "before malloc a %d area\n", areasize );
    area = malloc( areasize );
    if (area == NULL)
    {
        fprintf (stderr,
                "Cannot obtain a %d area: %s\n",
                areasize, strerror(errno));
        exit(1);
    }

    printf( "before free a %d area\n", areasize );

    if (area != NULL)
        free( area );
   
   /* area = NULL; */

    printf( "***** end of test *****\n");

    free( area );

    exit( 0) ;

}


the free after the end of test was added to show what happens
when trying to free an invalid storage/memory pointer

Code:

***** start of test *****
before malloc a 16777216 area
before free a 16777216 area
***** end of test *****
a.out(91122,0x7fffa2b75340) malloc: *** error for object 0x10eee6000: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6


BUT if You uncomment the area = NULL statement
free will not complain and just ignore the free

from the free man page
Quote:
The free() function deallocates the memory allocation pointed to by ptr.
If ptr is a NULL pointer, no operation is performed.


summarizing the whole shebang
ALWAYS CHECK THE RETURNED POINTER FOR NULL
AFTER A FREE ALWAYS SET THE POINTER TO NULL
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> ABENDS & Debugging All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts calling java code(on mainframe from c... elixir1986 COBOL Programming 1 Fri Nov 30, 2018 1:57 am
No new posts SFTP connection to Mainframe Shinoj Vijayakumar TSO/ISPF 4 Thu Nov 15, 2018 2:02 pm
No new posts Mainframe + Card domain exp. req. 5-6... capricorn Mainframe Jobs 0 Wed Oct 24, 2018 5:10 pm
No new posts 3-6 years - Mainframe Opennings in HS... Saikat Sengupta Mainframe Jobs 0 Mon Oct 22, 2018 2:57 pm
No new posts Ideas to motivate mainframe team mc77in All Other Mainframe Topics 6 Wed Oct 10, 2018 4:59 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us