Giter VIP home page Giter VIP logo

Comments (3)

bkannadassan avatar bkannadassan commented on September 13, 2024

Just to add

#include <dlfcn.h>
#include <execinfo.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <malloc.h>


void *
malloc (size_t size)
{
  const char *message = "malloc called\n";
  write (STDOUT_FILENO, message, strlen (message));
  void *next = dlsym (RTLD_NEXT, "malloc");
  return ((__typeof__ (malloc) *) next) (size);
}

int
main (void)
{
  /* This calls malloc.  */
  puts ("First call to backtrace.");
  void *buffer[10];
  backtrace (buffer, 10);
  puts ("First call to backtrace.");
  backtrace (buffer, 10);
  puts ("First call to backtrace.");
  backtrace (buffer, 10);
  /* This does not.  */
  puts ("Second call to backtrace.");
  backtrace (buffer, 10);
  malloc(10);
}

Compiled with

 g++ -g pop.cpp -lstdc++ -Wl,--no-as-needed -ldl -ltcmalloc -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free

Got output

malloc called
malloc called
malloc called
malloc called
malloc called
malloc called
malloc called
malloc called
malloc called
malloc called
malloc called
malloc called
malloc called
First call to backtrace.
malloc called
First call to backtrace.
First call to backtrace.
Second call to backtrace.
malloc called

from tcmalloc.

ckennelly avatar ckennelly commented on September 13, 2024

TCMalloc does not support being dynamically loaded in this fashion.

I think the behavior for whether backtrace calls malloc or not is a property of your libc, rather than TCMalloc itself.

from tcmalloc.

bkannadassan avatar bkannadassan commented on September 13, 2024

Is there any feature or provision that can be added to capture backtrace of each allocation and maintain the same in memory with extra few bytes in real time ?. We are looking for some implementation on the same lines.

from tcmalloc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.