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: 1114
Location: Oostende, Belgium

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: 10494
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 Can we call QMF proc from REXX ? batu544 CLIST & REXX 6 Fri Aug 03, 2018 11:03 am
No new posts Looking for immediate Job in mainfram... Chandan1993 Mainframe Jobs 0 Sun Jul 08, 2018 10:19 am
No new posts Transfer of mainframe file to PC in Z... maxsubrat JCL & VSAM 4 Thu May 17, 2018 11:35 am
No new posts using CALL PLIRETC(somevalu) Pedro PL/I & Assembler 1 Wed May 09, 2018 10:25 pm
No new posts Call COBOL or PLI with a click from w... vaibhav gs All Other Mainframe Topics 1 Mon Apr 16, 2018 7:29 pm

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