Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Jun 2001 02:25:42 -0700
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Zhihui Zhang <zzhang@cs.binghamton.edu>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: trace a library call
Message-ID:  <3B3AF816.3E752607@mindspring.com>
References:  <Pine.SOL.4.21.0106272231010.22637-100000@opal>

next in thread | previous in thread | raw e-mail | index | archive | help
Zhihui Zhang wrote:
> 
> Suppose I write a program that calls sbrk(). How can I trace into the
> function sbrk()? In this particular case, I want to know whether
> sbrk() calls the function in file lib/libstand/sbrk.c or sys/sbrk.S.
> Sometimes it is nice to see what system call is eventually called as well.
> I know dynamic linking may make this hard. But is there a way to do
> this? Thanks.

sbrk() is a system call, not a library call.  It has a
stub that just loads a register with the call ID and
does an INT 0x80.

You can't "trace into" it, since you are in a user space
program.

If you want to see how it works, the sources are in /sys;
but all it does is add pages to the end of the address
space, in the heap.

If you are having problems with it, you are probably using
sbrk() and malloc() in the same program.  Don't do that;
malloc() traditionally calls sbrk() to get pages, so you
will have the same effect as trying to use fopen() and
open() in the same program: mainly, that fd manipulation
routines can close/open/etc. fd's out from under file
pointers.  In the sbrk() case, there can be attempts to
(re)map pages to regions where they don't really belong.

-- Terry

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3B3AF816.3E752607>