public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Paulo Marques <pmarques@grupopie.com>
To: linux-os@analogic.com
Cc: Lethalman <lethalman@fyrebird.net>, linux-kernel@vger.kernel.org
Subject: Re: Let me know EIP address
Date: Tue, 04 Jan 2005 16:21:44 +0000	[thread overview]
Message-ID: <41DAC298.6070509@grupopie.com> (raw)
In-Reply-To: <Pine.LNX.4.61.0501041103300.4931@chaos.analogic.com>

linux-os wrote:
> On Tue, 4 Jan 2005, Lethalman wrote:
> 
>> I'm trying to get the EIP value from a simple program in C but i don't 
>> how to do it. I need it to know the current address position on the 
>> code segment.
>>
>> main() {
>>  long *eip;
>>  asm("mov %%eip,%0" : "=g"(eip));
>>  printf("%p\n", eip);
>> }
>>
>> Unfortunately EIP is not that kind of register :P
>> Does anyone know how to get EIP?
>>
> 
> You get the offset of a label, i.e., "foo:\t movl $foo,%0\n" in the asm 
> code.

Or use a gcc extension, so that you don't have to write assembly code:

int main(int argc, char *argv[])
{
   address:
     printf("this is my address %p\n", &&address);
   return 0;
}

-- 
Paulo Marques - www.grupopie.com

"A journey of a thousand miles begins with a single step."
Lao-tzu, The Way of Lao-tzu


  reply	other threads:[~2005-01-04 16:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-04 15:18 Let me know EIP address Lethalman
2005-01-04 16:05 ` linux-os
2005-01-04 16:21   ` Paulo Marques [this message]
2005-01-04 16:10 ` Paolo Ornati
2005-01-04 17:50   ` Bernd Eckenfels

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=41DAC298.6070509@grupopie.com \
    --to=pmarques@grupopie.com \
    --cc=lethalman@fyrebird.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-os@analogic.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox