3 Replies Latest reply on Nov 8, 2011 5:50 PM by suravee

    drill down to C functions


      Hi all,

      I am a newbie to CodeAnalyst and I would really like your help.

      As we all know, functions offered by C libraries, like malloc, free etc, have their own code. When I want to analyze a C program with CodeAnalyst, I try to drill down to these functions, specifically malloc, and the only thing I see is a weird assembly code which shows that a call is being made to the code of malloc!!!

      Is there a way to see the malloc's code (in C preferably)? Should I include more files in the working directory? Which are these files and how can I include them?

      Thank you all

        • drill down to C functions

          I assume if it is a precompiled library it won't include the original C source, so there is nothing to see.

            • drill down to C functions

              After the answer of Antzrhere, I tried the following trick. I downloaded the folder of glibc-2.13 and saved it in the desktop. So, instead of using the precompiled libraries, I used the files that are contained in the glibc-2.13 folder. The program was perfectly compiled and executed. However when I drilled down to the source, with CodeAnalyst, and double-clicked the following instruction:

              int *ptr = (int *) malloc(10 * sizeof (int));

              it showed me the following instructions:

              mov    $0x28,%edi              bf 28 00 00 00                               
              callq  400470 <malloc@plt>     e8 d3 fe ff ff                               
              mov    %rax,-0x10(%rbp)        48 89 45 f0

              which are not instructions of malloc function but just a call to it. Is there a proper configuration that I should do?




                • drill down to C functions

                  Since you are linking to a shared library, when you call a function which is in the shared library, it will actually call the "Procedure Linkage Table (PLT)" as part of dynamic linking for ELF.

                  If you want to inspect malloc performance, you should be looking in the glibc module itself.  Another way is to compile your program to link statically (--static).  In this case, the "malloc" will be part of the executable.