From: Sterling Augustine <saugustine@google.com>
To: Mark Manning <mark4th@gmail.com>
Cc: gdb@sourceware.org
Subject: Re: back into the thread....
Date: Tue, 12 Nov 2013 22:42:00 -0000 [thread overview]
Message-ID: <CAEG7qUx69s2cdp4XY3cGtAakDQAoSrGnbhgvvLxUzZG+rJKC_g@mail.gmail.com> (raw)
In-Reply-To: <CAPGNrUX7TA-4eCrrP=sD9G6oNe5Kw=eWPm_jm-D7=9ZTz-v6BA@mail.gmail.com>
This feature clearly works.
On Tue, Nov 12, 2013 at 2:08 PM, Mark Manning <mark4th@gmail.com> wrote:
> Got a reply from someone here about my problems with gdb but i cannot
> figure out how to reply all and googles reply always top posts my
> replies. Also i still have the same issue in that i cannot execute
> code that is not part of the original executables object. any
> additional code written into memory by my compiler is not executable
> yet the person who replied to me said that it SHOULD be possible as he
> does it all the time.
>
> this is a version of gdb running on an arm target (beagle board xm)
> under a gentoo linux install - is this a bug injected into gdb by some
> gentoo snafu?
If gdb doesn't think the memory is accessible, then it probably isn't.
The following test-case works perfectly well for gdb. You may want to
be sure that you are following all the correct steps in your code
generator, particularly the posix_memalign and mprotect. Otherwise
your code will take an unexpected segfault. I can set a breakpoint at
dst and stepi through it no problem.
The contents of bytes comes from compiling
int foo(int x) { return x; }
at O2 and then copying the resulting bytes into the array. You would
want to do something similar to get ARM results. Be sure it doesn't
have relocations.
=====
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <string.h>
#include <malloc.h>
const char bytes[] = { 0x89, 0xf8, 0xc3 };
#define EXEC_BYTES sizeof(bytes)
typedef int(*function_ptr)(int);
int main(int argc, char *argv[])
{
int test_val;
int return_val;
function_ptr dst = malloc(EXEC_BYTES);
if (posix_memalign((void **) &dst, 4096*8, EXEC_BYTES) != 0) {
printf("can't allocate.\n");
exit (-1);
}
if (mprotect(dst, EXEC_BYTES, PROT_READ|PROT_WRITE|PROT_EXEC) != 0) {
printf("can't mprotect\n");
exit (-1);
}
if (argc > 1)
test_val = atoi(argv[1]);
memcpy(dst, bytes, EXEC_BYTES);
return_val = dst(test_val);
printf("return val was %d\n", return_val);
return 0;
}
next prev parent reply other threads:[~2013-11-12 22:42 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-12 22:09 Mark Manning
2013-11-12 22:42 ` Sterling Augustine [this message]
2013-11-12 22:47 ` Sterling Augustine
2013-11-12 22:59 ` Mark Manning
2013-11-12 23:00 ` Mark Manning
[not found] ` <CAPGNrUUYWR7AOcFwTSxdEZa47E8iUJyfhzhWs+6jSc2+f4xqrg@mail.gmail.com>
2013-11-12 23:10 ` Sterling Augustine
2013-11-12 23:09 ` Mark Manning
2013-11-13 6:48 ` Phi Debian
2013-11-13 12:29 ` Mark Manning
2013-11-13 12:54 ` Phi Debian
2013-11-13 12:59 ` Mark Manning
2013-11-14 17:19 ` Arnab Bhaduri
2013-11-12 22:55 ` Mark Manning
2013-11-13 10:34 ` Pedro Alves
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=CAEG7qUx69s2cdp4XY3cGtAakDQAoSrGnbhgvvLxUzZG+rJKC_g@mail.gmail.com \
--to=saugustine@google.com \
--cc=gdb@sourceware.org \
--cc=mark4th@gmail.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