LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-20-2010, 02:37 PM   #1
cgopi24@gmail.com
LQ Newbie
 
Registered: Feb 2010
Posts: 1

Rep: Reputation: 0
using ld -wrap function to instrument


Hi All,

I am trying the wrap feature for the first time. I followed the instruction as mentioned in this link

http://sourceware.org/ml/binutils/2000-09/msg00083.html

but I am getting an error saying "undefine reference to __wrap_malloc

I followed all the steps, but the post was a decade old, I am sure something has changed? or am I missing something.

Appreciate your time in help me out!
 
Old 02-22-2010, 07:48 AM   #2
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Hey,

I checked this feature on my system, and it works perfectly. This is what I did:

Code:
#include <stdio.h>
#include <stdlib.h>

void *__real_malloc(size_t);

void *__wrap_malloc(size_t c)
{
        printf("My MALLOC called: %d\n", c);
        return __real_malloc(c);
}

int main (int argc, char *argv[])
{
        void *ptr = malloc(12);

        return 0;
}
And I compiled & run the code with:

Code:
[gcc wrap]$ gcc wrap.c -o wrap -Wl,-wrap,malloc
[gcc wrap]$ ./wrap
My MALLOC called: 12
I'm using

* gcc 4.4.3
* binutils 2.20.0.20091101


Maybe, you could post your code ...

- Andi -
 
Old 12-03-2010, 01:04 AM   #3
littlefang
LQ Newbie
 
Registered: Dec 2010
Posts: 1

Rep: Reputation: 0
May be your code needs extern C
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Do you play a musical instrument? PatrickMay16 General 25 01-07-2010 12:44 PM
pdf reader instrument linuxsavar General 2 05-16-2007 10:04 AM
"enscript --word-wrap" does not wrap line of text file powah Linux - General 3 05-16-2006 09:12 PM
Do you play any instrument? Eits0 General 50 11-13-2005 02:38 PM
Does anybody else play an instrument? Joey.Dale General 25 10-27-2004 09:22 PM


All times are GMT -5. The time now is 03:08 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration