michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: michael@0: A library that can be LD_PRELOAD-ed to dump a function's address on michael@0: function entry. michael@0: michael@0: */ michael@0: michael@0: #include michael@0: michael@0: /** michael@0: * When compiled with `-pg' (or even just `-p'), gcc inserts a call to michael@0: * |mcount| in each function prologue. This implementation of |mcount| michael@0: * will grab the return address from the stack, and write it to stdout michael@0: * as a binary stream, creating a gross execution trace the michael@0: * instrumented program. michael@0: * michael@0: * For more info on gcc inline assembly, see: michael@0: * michael@0: * michael@0: * michael@0: */ michael@0: void michael@0: mcount() michael@0: { michael@0: register unsigned int caller; michael@0: unsigned int buf[1]; michael@0: michael@0: // Grab the return address. michael@0: asm("movl 4(%%esp),%0" michael@0: : "=r"(caller)); michael@0: michael@0: buf[0] = caller; michael@0: write(STDOUT_FILENO, buf, sizeof buf[0]); michael@0: }