public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Fwd: [PATCH 1/1] x86: Add process memory layout to coredump file
       [not found] <CAE04G=Bu4WnU9SYU9u3-ap6OrBEjWONK8TA8bYBy5OSCCzzDqg@mail.gmail.com>
@ 2011-12-13 12:36 ` t cheney
       [not found] ` <m2y5uknqjk.fsf@firstfloor.org>
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: t cheney @ 2011-12-13 12:36 UTC (permalink / raw)
  To: binutils
  Cc: gdb-patches, jan.kratochvil, viro, linux-fsdevel, crash-catcher,
	cdmalord

---------- Forwarded message ----------
From: t cheney <cdmalord@gmail.com>
Date: Sat, 10 Dec 2011 22:37:02 +0800
Subject: [PATCH 1/1] x86: Add process memory layout to coredump file
To: linux-kernel@vger.kernel.org
Cc: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org

This patch just add memory layout(same as /proc/pid/maps) to
coredump file. The layout is appended to corenote segment with
flag NT_MAPS=7.

Signed-off-by: cheney <cdmalord@gmail.com>
---
 fs/binfmt_elf.c     |  210 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 include/linux/elf.h |    1 +
 2 files changed, 208 insertions(+), 3 deletions(-)

diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 21ac5ee..d9d07f4 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -35,6 +35,7 @@
 #include <asm/uaccess.h>
 #include <asm/param.h>
 #include <asm/page.h>
+#include <linux/seq_file.h>

 static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs);
 static int load_elf_library(struct file *);
@@ -1200,6 +1201,12 @@ static int notesize(struct memelfnote *en)
 #define DUMP_WRITE(addr, nr, foffset)	\
 	do { if (!dump_write(file, (addr), (nr))) return 0; *foffset +=
(nr); } while(0)

+static struct vm_area_struct *first_vma(struct task_struct *tsk,
+	struct vm_area_struct *gate_vma);
+static struct vm_area_struct *next_vma(struct vm_area_struct *this_vma,
+	struct vm_area_struct *gate_vma);
+/*extern char *mangle_path(char *s, char *p, char *esc);
+*/
 static int alignfile(struct file *file, loff_t *foffset)
 {
 	static const char buf[4] = { 0, };
@@ -1207,6 +1214,156 @@ static int alignfile(struct file *file, loff_t *foffset)
 	return 1;
 }

+static int pad_spaces(char *p, int len)
+{
+	int i;
+	len = 25 + sizeof(void *) * 6 - len;
+	if (len < 1)
+		len = 1;
+	i = len;
+	while (i--)
+		*p++ = ' ';
+	return len;
+}
+
+const char *get_vma_name(struct vm_area_struct *vma)
+{
+	const char *name = arch_vma_name(vma);
+	if (!name) {
+		struct mm_struct *mm = vma->vm_mm;
+		if (mm) {
+			if (vma->vm_start <= mm->brk &&
+				vma->vm_end >= mm->start_brk) {
+				name = "[heap]";
+			} else if (vma->vm_start <= mm->start_stack &&
+				vma->vm_end >= mm->start_stack) {
+				name = "[stack]";
+			}
+		} else {
+			name = "[vdso]";
+		}
+	}
+	return name;
+}
+
+/*  handle memory map in core
+ *  if filp=0 it just calculate the size of maps.
+ */
+static int core_handle_maps(struct file *file, struct memelfnote *notes,
+		loff_t *foffset)
+{
+	size_t maps_size = 0;
+	size_t len;
+	size_t space;
+	struct vm_area_struct *vma, *gate_vma;
+	int flags;
+	struct inode *inode;
+	unsigned long ino;
+	unsigned long long pgoff;
+	unsigned long start, end;
+	dev_t dev;
+	char *esc = "\n";
+	char *p;
+	char *s;
+	char *buf = notes->data;
+	size_t core_limit = notes->datasz;
+	gate_vma = get_gate_vma(current->mm);
+
+	for (vma = first_vma(current, gate_vma); vma != NULL;
+		vma = next_vma(vma, gate_vma)) {
+		flags = vma->vm_flags;
+		ino = 0;
+		dev = 0;
+		space = 0;
+		inode = NULL;
+		pgoff = 0;
+		len = 0;
+		if (vma->vm_file) {
+			inode = vma->vm_file->f_dentry->d_inode;
+			dev = inode->i_sb->s_dev;
+			ino = inode->i_ino;
+			pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
+		}
+		start = vma->vm_start;
+		if (stack_guard_page_start(vma, start))
+			start += PAGE_SIZE;
+		end = vma->vm_end;
+		if (stack_guard_page_end(vma, end))
+			end -= PAGE_SIZE;
+		len = sprintf(buf, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu",
+			start,
+			end,
+			flags & VM_READ ? 'r' : '-',
+			flags & VM_WRITE ? 'w' : '-',
+			flags & VM_EXEC ? 'x' : '-',
+			flags & VM_MAYSHARE ? 's' : 'p',
+			pgoff,
+			MAJOR(dev), MINOR(dev), ino);
+		maps_size += len;
+		if (file) {
+			if (maps_size > core_limit)
+				break;
+			DUMP_WRITE(buf, len, foffset);
+		}
+		if (vma->vm_file) {
+			space = pad_spaces(buf, len);
+			s = buf + space;
+			p = d_path(&vma->vm_file->f_path, s, maps_size-1);
+			if (!IS_ERR(p)) {
+				char *last;
+				last = mangle_path(s, p, esc);
+				len = last - buf;
+				maps_size += len;
+				if (file) {
+					if (maps_size > core_limit)
+						 break;
+					DUMP_WRITE(buf, len, foffset);
+				}
+			}
+		} else {
+			const char *name = get_vma_name(vma);
+			if (name) {
+				space = pad_spaces(buf, len);
+				maps_size += space;
+				maps_size += strlen(name);
+				if (file) {
+					if (maps_size > core_limit)
+						 break;
+					DUMP_WRITE(buf, space, foffset);
+					DUMP_WRITE(name, strlen(name), foffset);
+				}
+			}
+		}
+		maps_size++;
+		if (file) {
+			if (maps_size > core_limit)
+				break;
+			DUMP_WRITE("\n", 1, foffset);
+		}
+	}
+	return maps_size;
+}
+
+static int writemaps(struct file *file, struct memelfnote *men,
+	loff_t *foffset)
+{
+	struct elf_note en;
+	en.n_namesz = strlen(men->name) + 1;
+	en.n_descsz = men->datasz;
+	en.n_type = men->type;
+
+	DUMP_WRITE(&en, sizeof(en), foffset);
+	DUMP_WRITE(men->name, en.n_namesz, foffset);
+	if (!alignfile(file, foffset))
+		return 0;
+	if (!core_handle_maps(file, men, foffset))
+		return 0;
+	if (!alignfile(file, foffset))
+		return 0;
+
+	return 1;
+}
+
 static int writenote(struct memelfnote *men, struct file *file,
 			loff_t *foffset)
 {
@@ -1374,6 +1531,8 @@ struct elf_note_info {
 	struct elf_thread_core_info *thread;
 	struct memelfnote psinfo;
 	struct memelfnote auxv;
+	/* maps is for memory layout */
+	struct memelfnote maps;
 	size_t size;
 	int thread_notes;
 };
@@ -1460,6 +1619,7 @@ static int fill_note_info(struct elfhdr *elf, int phdrs,
 	struct elf_prpsinfo *psinfo;
 	struct core_thread *ct;
 	unsigned int i;
+	int maps_size;

 	info->size = 0;
 	info->thread = NULL;
@@ -1468,6 +1628,21 @@ static int fill_note_info(struct elfhdr *elf, int phdrs,
 	if (psinfo == NULL)
 		return 0;

+	info->maps.data = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	if (info->maps.data == NULL) {
+		kfree(psinfo);
+		return 0;
+	}
+	/* Just calculate maps' size  */
+	maps_size = core_handle_maps(NULL, &info->maps, NULL);
+	if (!maps_size) {
+		kfree(psinfo);
+		kfree(info->maps.data);
+		return 0;
+	}
+	fill_note(&info->maps, "CORE", NT_MAPS, maps_size, info->maps.data);
+	info->size += notesize(&info->maps);
+
 	fill_note(&info->psinfo, "CORE", NT_PRPSINFO, sizeof(*psinfo), psinfo);

 	/*
@@ -1572,6 +1747,10 @@ static int write_note_info(struct elf_note_info *info,
 		t = t->next;
 	} while (t);

+	/* Write maps */
+	if (!writemaps(file, &info->maps, foffset))
+		return 0;
+
 	return 1;
 }

@@ -1588,6 +1767,7 @@ static void free_note_info(struct elf_note_info *info)
 		kfree(t);
 	}
 	kfree(info->psinfo.data);
+	kfree(info->maps.data);
 }

 #else
@@ -1648,6 +1828,7 @@ struct elf_note_info {
 	struct memelfnote *notes;
 	struct elf_prstatus *prstatus;	/* NT_PRSTATUS */
 	struct elf_prpsinfo *psinfo;	/* NT_PRPSINFO */
+	char *maps;                     /* NT_MAPS */
 	struct list_head thread_list;
 	elf_fpregset_t *fpu;
 #ifdef ELF_CORE_COPY_XFPREGS
@@ -1663,12 +1844,16 @@ static int elf_note_info_init(struct
elf_note_info *info)
 	INIT_LIST_HEAD(&info->thread_list);

 	/* Allocate space for six ELF notes */
-	info->notes = kmalloc(6 * sizeof(struct memelfnote), GFP_KERNEL);
+	/* Add maps into notes */
+	info->notes = kmalloc((6+1) * sizeof(struct memelfnote), GFP_KERNEL);
 	if (!info->notes)
 		return 0;
+	info->maps = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	if (!info->maps)
+		goto notes_free;
 	info->psinfo = kmalloc(sizeof(*info->psinfo), GFP_KERNEL);
 	if (!info->psinfo)
-		goto notes_free;
+		goto maps_free;
 	info->prstatus = kmalloc(sizeof(*info->prstatus), GFP_KERNEL);
 	if (!info->prstatus)
 		goto psinfo_free;
@@ -1689,6 +1874,8 @@ static int elf_note_info_init(struct elf_note_info *info)
 	kfree(info->prstatus);
  psinfo_free:
 	kfree(info->psinfo);
+ maps_free:
+	kfree(info->maps);
  notes_free:
 	kfree(info->notes);
 	return 0;
@@ -1699,6 +1886,7 @@ static int fill_note_info(struct elfhdr *elf, int phdrs,
 			  long signr, struct pt_regs *regs)
 {
 	struct list_head *t;
+	int maps_size;

 	if (!elf_note_info_init(info))
 		return 0;
@@ -1761,6 +1949,14 @@ static int fill_note_info(struct elfhdr *elf, int phdrs,
 			  sizeof(*info->xfpu), info->xfpu);
 #endif

+	info->notes[info->numnote].data = info->maps;
+	/* Just calculate maps's size */
+	maps_size = core_handle_maps(NULL, info->notes + info->numnote, NULL);
+	if (!maps_size)
+		return 0;
+	fill_note(info->notes + info->numnote++, "CORE", NT_MAPS,
+		maps_size, info->maps);
+
 	return 1;
 }

@@ -1783,9 +1979,16 @@ static int write_note_info(struct elf_note_info *info,
 	int i;
 	struct list_head *t;

-	for (i = 0; i < info->numnote; i++)
+	for (i = 0; i < info->numnote; i++) {
+		/* Write maps */
+		if (info->notes[i].type == NT_MAPS) {
+			if (!writemaps(file, info->notes + i, foffset))
+				return 0;
+			continue;
+		}
 		if (!writenote(info->notes + i, file, foffset))
 			return 0;
+	}

 	/* write out the thread status notes section */
 	list_for_each(t, &info->thread_list) {
@@ -1812,6 +2015,7 @@ static void free_note_info(struct elf_note_info *info)
 	kfree(info->psinfo);
 	kfree(info->notes);
 	kfree(info->fpu);
+	kfree(info->maps);
 #ifdef ELF_CORE_COPY_XFPREGS
 	kfree(info->xfpu);
 #endif
diff --git a/include/linux/elf.h b/include/linux/elf.h
index 31f0508..b9d710b 100644
--- a/include/linux/elf.h
+++ b/include/linux/elf.h
@@ -381,6 +381,7 @@ typedef struct elf64_shdr {
 #define NT_PRPSINFO	3
 #define NT_TASKSTRUCT	4
 #define NT_AUXV		6
+#define NT_MAPS         7
 #define NT_PRXFPREG     0x46e62b7f      /* copied from
gdb5.1/include/elf/common.h */
 #define NT_PPC_VMX	0x100		/* PowerPC Altivec/VMX registers */
 #define NT_PPC_SPE	0x101		/* PowerPC SPE/EVR registers */
-- 
1.5.3.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Fwd: [PATCH 1/1] x86: Add process memory layout to coredump file
       [not found]     ` <CAE04G=A7WWG4WDoTfcBVMsxNB2xndVTq4s6DPdsyDEca4Up=SQ@mail.gmail.com>
@ 2011-12-13 12:37       ` t cheney
  0 siblings, 0 replies; 4+ messages in thread
From: t cheney @ 2011-12-13 12:37 UTC (permalink / raw)
  To: binutils
  Cc: gdb-patches, jan.kratochvil, viro, linux-fsdevel, crash-catcher,
	cdmalord

---------- Forwarded message ----------
From: t cheney <cdmalord@gmail.com>
Date: Sun, 11 Dec 2011 21:19:22 +0800
Subject: Re: [PATCH 1/1] x86: Add process memory layout to coredump file
To: Andi Kleen <andi@firstfloor.org>
Cc: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk,
linux-fsdevel@vger.kernel.org

This is readelf's patch which can retrieve maps in coredump
file, and it is based on binutils-2.21.1.
Usage: ./readelf -m coredumpfile
https://github.com/cdma/coredumpmap/blob/dev/readelf.c
https://github.com/cdma/coredumpmap/blob/dev/common.h

Alternately, following is diff's result:
changed files:
./binutils-2.21.1/binutils/readelf.c
./binutils-2.21.1/include/elf/common.h

diff -u ./binutils-2.21.1/binutils/readelf.c
./binutils-2.21.1/binutils/readelf.c.orig
--- ./binutils-2.21.1/binutils/readelf.c        2011-12-07
14:54:45.000000000 -0500
+++ ./binutils-2.21.1/binutils/readelf.c.orig   2011-12-07
14:53:43.000000000 -0500
@@ -196,7 +196,6 @@
 static int do_notes;
 static int do_archive_index;
 static int is_32bit_elf;
-static int do_maps;

 struct group_list
 {
@@ -3072,7 +3071,6 @@
  {"dyn-syms",        no_argument, 0, OPTION_DYN_SYMS},
  {"relocs",          no_argument, 0, 'r'},
  {"notes",           no_argument, 0, 'n'},
-  {"maps",            no_argument, 0, 'm'},
  {"dynamic",         no_argument, 0, 'd'},
  {"arch-specific",    no_argument, 0, 'A'},
  {"version-info",     no_argument, 0, 'V'},
@@ -3112,7 +3110,6 @@
     --symbols           An alias for --syms\n\
  --dyn-syms             Display the dynamic symbol table\n\
  -n --notes             Display the core notes (if present)\n\
-  -m --maps              Display the core maps (if present)\n\
  -r --relocs            Display the relocations (if present)\n\
  -u --unwind            Display the unwind info (if present)\n\
  -d --dynamic           Display the dynamic section (if present)\n\
@@ -3231,7 +3228,7 @@
    usage (stderr);

  while ((c = getopt_long
-         (argc, argv, "ADHINR:SVWacdeghi:lnp:rstuvw::x:m", options,
NULL)) != EOF)
+         (argc, argv, "ADHINR:SVWacdeghi:lnp:rstuvw::x:", options,
NULL)) != EOF)
    {
      switch (c)
       {
@@ -3354,9 +3351,6 @@
       case 'W':
         do_wide++;
         break;
-       case 'm':
-         do_maps++;
-         break;
       default:
         /* xgettext:c-format */
         error (_("Invalid option '-%c'\n"), c);
@@ -3370,7 +3364,7 @@
      && !do_segments && !do_header && !do_dump && !do_version
      && !do_histogram && !do_debugging && !do_arch && !do_notes
      && !do_section_groups && !do_archive_index
-      && !do_dyn_syms && !do_maps)
+      && !do_dyn_syms)
    usage (stderr);
  else if (argc < 3)
    {
@@ -11855,8 +11849,6 @@
       return _("NT_LWPSINFO (lwpsinfo_t structure)");
      case NT_WIN32PSTATUS:
       return _("NT_WIN32PSTATUS (win32_pstatus structure)");
-      case NT_MAPS:
-       return _("NT_MAPS (maps info)");
      default:
       break;
      }
@@ -11970,9 +11962,6 @@
 {
  const char * name = pnote->namesz ? pnote->namedata : "(NONE)";
  const char * nt;
-
-  if (do_maps && pnote->type != NT_MAPS)
-       return 0;

  if (pnote->namesz == 0)
    /* If there is no note name, then use the default set of
@@ -12000,13 +11989,6 @@
      nt = get_note_type (pnote->type);

  printf ("  %s\t\t0x%08lx\t%s\n", name, pnote->descsz, nt);
-  if (do_maps && pnote->type == NT_MAPS)
-  {
-      pnote->descdata[pnote->descsz] = 0;
-      printf("Maps is following:\n");
-      printf("%s\n",pnote->descdata);
-  }
-
  return 1;
 }

@@ -12093,6 +12075,7 @@
       }

      res &= process_note (& inote);
+
      if (temp != NULL)
       {
         free (temp);
@@ -12150,7 +12133,7 @@
 process_notes (FILE * file)
 {
  /* If we have not been asked to display the notes then do nothing.  */
-  if (! do_notes && !do_maps)
+  if (! do_notes)
    return 1;

  if (elf_header.e_type != ET_CORE)


diff -u ./binutils-2.21.1/include/elf/common.h
./binutils-2.21.1/include/elf/common.h.orig
--- ./binutils-2.21.1/include/elf/common.h      2011-12-07
14:56:02.000000000 -0500
+++ ./binutils-2.21.1/include/elf/common.h.orig 2011-12-07
14:55:45.000000000 -0500
@@ -518,7 +518,6 @@
 #define NT_PRPSINFO    3               /* Contains copy of prpsinfo struct */
 #define NT_TASKSTRUCT  4             /* Contains copy of task struct */
 #define NT_AUXV                6            /* Contains copy of Elfxx_auxv_t */
-#define NT_MAPS         7               /* Contains copy of maps*/
 #define NT_PRXFPREG    0x46e62b7f      /* Contains a user_xfpregs_struct; */
                                       /*   note name must be "LINUX".  */
 #define NT_PPC_VMX     0x100           /* PowerPC Altivec/VMX registers */



On 12/11/11, t cheney <cdmalord@gmail.com> wrote:
> On 12/11/11, Andi Kleen <andi@firstfloor.org> wrote:
>> t cheney <cdmalord@gmail.com> writes:
>>
>>> This patch just add memory layout(same as /proc/pid/maps) to
>>> coredump file. The layout is appended to corenote segment with
>>> flag NT_MAPS=7.
>>
>> Seems like a reasonable idea, but can you please share code with
>> the proc implementation?
> Yes, I will post it in following mail.
>>
>> It's a bit unusal to have ASCII in a coredump, but I suppose expressing
>> this in binary would be somewhat ugly.
>>
>>> +	char *buf = notes->data;
>>> +	size_t core_limit = notes->datasz;
>>> +	gate_vma = get_gate_vma(current->mm);
>>> +
> The maps info is appended to core notes segment in which there are all
> ASCII text such as regs,signal and thread info.
>>
>> It seems a bit dubious to do this without locking even in a core dump.
>>
>>> +	for (vma = first_vma(current, gate_vma); vma != NULL;
>>> +		vma = next_vma(vma, gate_vma)) {
>>> +		flags = vma->vm_flags;
>>> +		maps_size += len;
>>> +		if (file) {
>>> +			if (maps_size > core_limit)
>>> +				break;
>>
>> You have a one-off bug here. Also below.
>>
>>> +			DUMP_WRITE(buf, len, foffset);
>>> +		}
>>
> Because proceses that could change vma pages are blocked in do_exit,
> here vma pages are safe.
>>
>> -Andi
>> --
>> ak@linux.intel.com -- Speaking for myself only
>>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] x86: Add process memory layout to coredump file
       [not found]   ` <20111212210328.GA29248@host2.jankratochvil.net>
@ 2011-12-18 10:11     ` t cheney
  0 siblings, 0 replies; 4+ messages in thread
From: t cheney @ 2011-12-18 10:11 UTC (permalink / raw)
  To: Jan Kratochvil
  Cc: gdb, linux-kernel, viro, linux-fsdevel, gdb-patches, binutils

Thank your suggestion.

changed files:
./binutils-2.21.1/binutils/readelf.c
./binutils-2.21.1/include/elf/common.h

diff -u ./binutils-2.21.1/binutils/readelf.c
./binutils-2.21.1/binutils/readelf.c.orig
--- ./binutils-2.21.1/binutils/readelf.c        2011-12-07
14:54:45.000000000 -0500
+++ ./binutils-2.21.1/binutils/readelf.c.orig   2011-12-07
14:53:43.000000000 -0500
@@ -196,7 +196,6 @@
 static int do_notes;
 static int do_archive_index;
 static int is_32bit_elf;
-static int do_maps;

 struct group_list
 {
@@ -3072,7 +3071,6 @@
   {"dyn-syms",        no_argument, 0, OPTION_DYN_SYMS},
   {"relocs",          no_argument, 0, 'r'},
   {"notes",           no_argument, 0, 'n'},
-  {"maps",            no_argument, 0, 'm'},
   {"dynamic",         no_argument, 0, 'd'},
   {"arch-specific",    no_argument, 0, 'A'},
   {"version-info",     no_argument, 0, 'V'},
@@ -3112,7 +3110,6 @@
      --symbols           An alias for --syms\n\
   --dyn-syms             Display the dynamic symbol table\n\
   -n --notes             Display the core notes (if present)\n\
-  -m --maps              Display the core maps (if present)\n\
   -r --relocs            Display the relocations (if present)\n\
   -u --unwind            Display the unwind info (if present)\n\
   -d --dynamic           Display the dynamic section (if present)\n\
@@ -3231,7 +3228,7 @@
     usage (stderr);

   while ((c = getopt_long
-         (argc, argv, "ADHINR:SVWacdeghi:lnp:rstuvw::x:m", options,
NULL)) != EOF)
+         (argc, argv, "ADHINR:SVWacdeghi:lnp:rstuvw::x:", options,
NULL)) != EOF)
     {
       switch (c)
        {
@@ -3354,9 +3351,6 @@
        case 'W':
          do_wide++;
          break;
-       case 'm':
-         do_maps++;
-         break;
        default:
          /* xgettext:c-format */
          error (_("Invalid option '-%c'\n"), c);
@@ -3370,7 +3364,7 @@
       && !do_segments && !do_header && !do_dump && !do_version
       && !do_histogram && !do_debugging && !do_arch && !do_notes
       && !do_section_groups && !do_archive_index
-      && !do_dyn_syms && !do_maps)
+      && !do_dyn_syms)
     usage (stderr);
   else if (argc < 3)
     {
@@ -11855,8 +11849,6 @@
        return _("NT_LWPSINFO (lwpsinfo_t structure)");
       case NT_WIN32PSTATUS:
        return _("NT_WIN32PSTATUS (win32_pstatus structure)");
-      case NT_MAPS:
-       return _("NT_MAPS (maps info)");
       default:
        break;
       }
@@ -11970,9 +11962,6 @@
 {
   const char * name = pnote->namesz ? pnote->namedata : "(NONE)";
   const char * nt;
-
-  if (do_maps && pnote->type != NT_MAPS)
-       return 0;

   if (pnote->namesz == 0)
     /* If there is no note name, then use the default set of
@@ -12000,13 +11989,6 @@
       nt = get_note_type (pnote->type);

   printf ("  %s\t\t0x%08lx\t%s\n", name, pnote->descsz, nt);
-  if (do_maps && pnote->type == NT_MAPS)
-  {
-      pnote->descdata[pnote->descsz] = 0;
-      printf("Maps is following:\n");
-      printf("%s\n",pnote->descdata);
-  }
-
   return 1;
 }

@@ -12093,6 +12075,7 @@
        }

       res &= process_note (& inote);
+
       if (temp != NULL)
        {
          free (temp);
@@ -12150,7 +12133,7 @@
 process_notes (FILE * file)
 {
   /* If we have not been asked to display the notes then do nothing.  */
-  if (! do_notes && !do_maps)
+  if (! do_notes)
     return 1;

   if (elf_header.e_type != ET_CORE)

diff -u ./binutils-2.21.1/include/elf/common.h
./binutils-2.21.1/include/elf/common.h.orig
--- ./binutils-2.21.1/include/elf/common.h      2011-12-07
14:56:02.000000000 -0500
+++ ./binutils-2.21.1/include/elf/common.h.orig 2011-12-07
14:55:45.000000000 -0500
@@ -518,7 +518,6 @@
 #define NT_PRPSINFO    3               /* Contains copy of prpsinfo struct */
 #define NT_TASKSTRUCT  4               /* Contains copy of task struct */
 #define NT_AUXV                6               /* Contains copy of
Elfxx_auxv_t */
-#define NT_MAPS         7               /* Contains copy of maps*/
 #define NT_PRXFPREG    0x46e62b7f      /* Contains a user_xfpregs_struct; */
                                        /*   note name must be "LINUX".  */
 #define NT_PPC_VMX     0x100           /* PowerPC Altivec/VMX registers */


On 12/13/11, Jan Kratochvil <jan.kratochvil@redhat.com> wrote:
> On Sun, 11 Dec 2011 15:10:00 +0100, t cheney wrote:
>> This patch just add memory layout(same as /proc/pid/maps) to
>> coredump file. The layout is appended to corenote segment with
>> flag NT_MAPS=7.
>
> FYI this has been solved by ABRT - Automated Bug-Reporting Tool
> 	https://fedorahosted.org/abrt/
> 	(it is distro-neutral despite its homepage)
>
> Core file is there a subdirectory where the core file is just one of the
> many
> associated files:
> /var/spool/abrt/ccpp-*:
> 	abrt_version analyzer architecture cmdline component coredump count
> 	dso_list environ executable hostname kernel maps os_release package
> 	pid pwd reason time uid username uuid var_log_messages
>
> More info files are being continually added, such as /proc/PID/fd{,info}/
> mapping at the crash dump time etc.  You would need to add many more core
> file
> notes to make the core files useful for later analysis.
>
>
> Regards,
> Jan
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] x86: Add process memory layout to coredump file
       [not found] ` <20111214211652.GO2203@ZenIV.linux.org.uk>
@ 2011-12-18 12:38   ` t cheney
  0 siblings, 0 replies; 4+ messages in thread
From: t cheney @ 2011-12-18 12:38 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-kernel, linux-fsdevel, gdb-patches, binutils

On 12/15/11, Al Viro <viro@zeniv.linux.org.uk> wrote:
> On Sat, Dec 10, 2011 at 10:37:02PM +0800, t cheney wrote:
>> This patch just add memory layout(same as /proc/pid/maps) to
>> coredump file. The layout is appended to corenote segment with
>> flag NT_MAPS=7.
>
>> +		len = sprintf(buf, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu",
>> +			start,
>> +			end,
>> +			flags & VM_READ ? 'r' : '-',
>> +			flags & VM_WRITE ? 'w' : '-',
>> +			flags & VM_EXEC ? 'x' : '-',
>> +			flags & VM_MAYSHARE ? 's' : 'p',
>> +			pgoff,
>> +			MAJOR(dev), MINOR(dev), ino);
>
> Device numbers may be wider than 16 bits.
Yes, it should be:
len = sprintf(buf, "%08lx-%08lx %c%c%c%c %08llx %03x:%05x %lu",
and  corresponding change from 25 to 29 in function pad_spaces:
static int pad_spaces(char *p, int len)
{
       len = 29 + sizeof(void *) * 6 - len;

>
>> +			p = d_path(&vma->vm_file->f_path, s, maps_size-1);
>
> What if somebody renames the file (or, better yet, its parent directory)
> between two calls of that thing?
>
Yes, function core_handle_maps is called twice, first one just calculate size,
second one write maps into coredump file. If the pathname is changed,
the size may changed too.
If the new size is less than or same as origin, all maps string is
written to file.
If the new size is  more than  origin, just part is written to file,
the rest is ignored.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-12-18 12:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAE04G=Bu4WnU9SYU9u3-ap6OrBEjWONK8TA8bYBy5OSCCzzDqg@mail.gmail.com>
2011-12-13 12:36 ` Fwd: [PATCH 1/1] x86: Add process memory layout to coredump file t cheney
     [not found] ` <m2y5uknqjk.fsf@firstfloor.org>
     [not found]   ` <CAE04G=Bq+tyPnM+SVHUm+AQH4nLOy-KH7foRVNFs6GNdzpiX_Q@mail.gmail.com>
     [not found]     ` <CAE04G=A7WWG4WDoTfcBVMsxNB2xndVTq4s6DPdsyDEca4Up=SQ@mail.gmail.com>
2011-12-13 12:37       ` t cheney
     [not found] ` <CAE04G=D_OzrDRUOj-iVPJY5sNTLMfUKAeikks8TWMYOWvh6HeA@mail.gmail.com>
     [not found]   ` <20111212210328.GA29248@host2.jankratochvil.net>
2011-12-18 10:11     ` t cheney
     [not found] ` <20111214211652.GO2203@ZenIV.linux.org.uk>
2011-12-18 12:38   ` t cheney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).