gabriel rosenkoetter on Tue, 24 Sep 2002 03:10:09 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] [C QUESTION] how to tell caller of a function


On Mon, Sep 23, 2002 at 07:55:16PM -0400, Fred K Ollinger wrote:
> I'm asking this on behalf of someone else, so I'm not quite sure. Is this
> difficult to do then? I heard that the caller gets pushed onto a stack
> somewhere. This might mean that the stack is worthless to me even if I can
> get to it b/c it probably has a bunch of hex numbers that mean something
> to the computer, but not me.

Exactly. What's on the stack is an address in memory (within the
text segment of a binary loaded in the heap, specifically, in most
processor architectures, but not all) that is the (assembly, not C)
instruction which called the function. There's no concept of C
function names at the level where the code is running unless you
compile them, as strings, into the binary. That's what your
compiler's debugging flag does, and the easiest way to get at those
strings is to step through the program in a debugger.

The only circumstance under which you'd want to be able to get at
and use this information on the fly is in the case of self-modifying
code... but if that's what you're trying to do, you wouldn't be
asking this question, because you *really* have to know how the
virtual machine operates to do that (and even then it's of fairly
questionalbe utility).

> So the compiler is protecting me from myself? Is there a way around this?

Um... around what? The compiler's not hiding anything from you, it's
doing exactly what it's supposed to be doing: translating a
high-level programming language (C, which is pretty easy for you to
understand and completely outside the ken of a processor, which
speaks an significantly more simple language) into low-level
instruction calls (which are obtuse to you, who have a hard time
holding a bunch of values in various registers without pen and
paper, but which the processor can grok with ease). It can also be
asked to relate that back to what you originally gave it. That's the
debugging flag. And you ask a running binary about its debugging
symbols by using a debugger.

-- 
gabriel rosenkoetter
gr@eclipsed.net

Attachment: pgp7oh92Tdzs9.pgp
Description: PGP signature