Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Mathieu Lacage <Mathieu.Lacage@sophia.inria.fr>
To: gdb@sourceware.org
Subject: Re: placing a breakpoint at a physical address on x86 with gdb
Date: Fri, 12 Jan 2007 12:48:00 -0000	[thread overview]
Message-ID: <1168606081.2789.38.camel@garfield.inria.fr> (raw)
In-Reply-To: <1168602087.2789.35.camel@garfield.inria.fr>

[-- Attachment #1: Type: text/plain, Size: 397 bytes --]

On Fri, 2007-01-12 at 12:41 +0100, Mathieu Lacage wrote:

> Yet another alternative would be to create a shared memory segment with
> shm_open, copy the code of my function in there, create multiple memory
> mappings with mmap (MAP_SHARED) on that shared memory segment and insert
> an int3 in the shared memory segment whenever needed.

and the attached test code demonstrates this.

Mathieu
-- 

[-- Attachment #2: test-mmap.c --]
[-- Type: text/x-csrc, Size: 2046 bytes --]

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <assert.h>
#include <errno.h>
#include <string.h>


#define BUFFER_SIZE (1024)

int main (int argc, char *argv[])
{
  int file_fd, shm_fd;
  struct stat stat_buffer;
  char buffer[BUFFER_SIZE];
  int retval;
  off_t left;
  file_fd = open ("./test-mmap.c", O_RDONLY);
  retval = fstat(file_fd, &stat_buffer);
  assert (retval != -1);
  shm_fd = shm_open ("my-test", O_RDWR | O_CREAT, S_IRWXU);
  assert (shm_fd != -1);
  retval = ftruncate (shm_fd, stat_buffer.st_size);
  assert (retval != -1);
  left = stat_buffer.st_size;
  while (left > 0) {
    off_t to_read;
    ssize_t actually_read;
    ssize_t actually_written;
    if (left > BUFFER_SIZE) {
      to_read = BUFFER_SIZE;
    } else {
      to_read = left;
    }
    actually_read = read (file_fd, buffer, to_read);
    assert (actually_read != -1);
    actually_written = write (shm_fd, buffer, actually_read);
    assert (actually_written == actually_read);
    left -= actually_read;
  }
  close (file_fd);

  printf ("done copying file to shared memory\n");

  // Here, we have a shared memory segment which contains the content of our file.

  {
    void *map_one;
    void *map_two;
    char *one;
    char *two;
    map_one = mmap (0, stat_buffer.st_size, PROT_READ | PROT_EXEC | PROT_WRITE, MAP_SHARED, shm_fd, 0);
    assert (map_one != MAP_FAILED);
    map_two = mmap (0, stat_buffer.st_size, PROT_READ | PROT_EXEC | PROT_WRITE, MAP_SHARED, shm_fd, 0);
    assert (map_two != MAP_FAILED);

    one = map_one;
    two = map_two;
    printf ("one=%c\n", one[10]);
    printf ("two=%c\n", two[10]);    
    one[10] = 'Y';
    msync (map_one, stat_buffer.st_size, MS_SYNC);
    printf ("one=%c\n", one[10]);
    printf ("two=%c\n", two[10]);    


    retval = munmap (map_one, stat_buffer.st_size);
    assert (retval != -1);
    retval = munmap (map_two, stat_buffer.st_size);
    assert (retval != -1);
  }


  return 0;
}

  reply	other threads:[~2007-01-12 12:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-12 11:42 Mathieu Lacage
2007-01-12 12:48 ` Mathieu Lacage [this message]
2007-01-12 13:46   ` help string for "break" command Mathieu Lacage
2007-01-12 13:49     ` Daniel Jacobowitz
2007-01-12 14:20       ` Mathieu Lacage
2007-01-12 14:26         ` Daniel Jacobowitz
2007-01-12 14:27         ` Bob Rossi
2007-01-12 14:34           ` Mathieu Lacage
2007-01-12 18:11       ` mathieu lacage
2007-01-12 23:26         ` Daniel Jacobowitz

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=1168606081.2789.38.camel@garfield.inria.fr \
    --to=mathieu.lacage@sophia.inria.fr \
    --cc=gdb@sourceware.org \
    /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