Skip to contentSkip to conversation

Fix the multithread program core thread message error

PATCH In review Hui Zhu 4 participants 11 messages Jun 30, 2009 – Jul 3, 2009

lore
Share & tools
lore

Hui Zhu

author
#0 lore raw

PATCH 1/1 Fix the multithread program core thread message error

Fix the multithread program core thread message error. The thread message of core file is generated in elf_dump_thread_status. The register values is set by elf_core_copy_task_regs in this function.
static inline int elf_core_copy_task_regs(struct task_struct *t,
elf_gregset_t* elfregs)
{

	return ELF_CORE_COPY_TASK_REGS(t, elfregs);
	return 0;
}

If a arch doesn't define ELF_CORE_COPY_TASK_REGS, This function will do nothing. Then the core file will not have the register message of thread.
So add elf_core_copy_regs to set regiser values if ELF_CORE_COPY_TASK_REGS doesn't define.

---
 elfcore.h |    2 ++
 1 file changed, 2 insertions(+)
include/linux/elfcore.h +0 -0
index 7605c5e..03ec167 100644
@@ -125,6 +125,8 @@ static inline int elf_core_copy_task_regs(struct

task_struct *t, elf_gregset_t*
#ifdef ELF_CORE_COPY_TASK_REGS

        return ELF_CORE_COPY_TASK_REGS(t, elfregs);
+#else
+       elf_core_copy_regs(elfregs, task_pt_regs(t));
 #endif
        return 0;

}

#1 lore raw

Hi, Hui.

Quoted 8 lines · Hui Zhu

Fix the multithread program core thread message error. The thread message of core file is generated in elf_dump_thread_status. The register values is set by elf_core_copy_task_regs in this function.
static inline int elf_core_copy_task_regs(struct task_struct *t,
elf_gregset_t* elfregs)
{

Quoted 8 lines
	return ELF_CORE_COPY_TASK_REGS(t, elfregs);
	return 0;
}

If a arch doesn't define ELF_CORE_COPY_TASK_REGS, This function will do nothing. Then the core file will not have the register message of thread.
So add elf_core_copy_regs to set regiser values if ELF_CORE_COPY_TASK_REGS doesn't define.

You forgot your Signed-off-by line. :)

Hmmm, this patch looks sane for me. But could you please send us your test program? i.e. how did you test this?

Thank you!

Quoted 23 lines

---
elfcore.h | 2 ++

1 file changed, 2 insertions(+)
include/linux/elfcore.h +0 -0
index 7605c5e..03ec167 100644
@@ -125,6 +125,8 @@ static inline int elf_core_copy_task_regs(struct

task_struct *t, elf_gregset_t*
#ifdef ELF_CORE_COPY_TASK_REGS

       return ELF_CORE_COPY_TASK_REGS(t, elfregs);
include/linux/elfcore.h +2 -0
+#else
+       elf_core_copy_regs(elfregs, task_pt_regs(t));
#endif
       return 0;
}

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

author
#2 lore raw

Hi Amerigo,

Thanks for your reply.

Quoted 22 lines · Amerigo Wang

Hi, Hui.

Quoted 8 lines · Hui Zhu

Fix the multithread program core thread message error. The thread message of core file is generated in elf_dump_thread_status.  The register values is set by elf_core_copy_task_regs in this function.
static inline int elf_core_copy_task_regs(struct task_struct *t, elf_gregset_t* elfregs) {

Quoted 8 lines

      return ELF_CORE_COPY_TASK_REGS(t, elfregs);
      return 0;
}
If a arch doesn't define ELF_CORE_COPY_TASK_REGS, This function will do nothing.  Then the core file will not have the register message of thread.
So add elf_core_copy_regs to set regiser values if ELF_CORE_COPY_TASK_REGS doesn't define.

Quoted 1 line

You forgot your Signed-off-by line. :)

Quoted 4 lines

Hmmm, this patch looks sane for me. But could you please send us your test program? i.e. how did you test this?

I test this issue in a arm board. My test code is:
#include <stdio.h>
#include <pthread.h>
#include <assert.h>

void td1(void * i)

{
	while (1)
	{
		printf ("1\n");
		sleep (1);
	}

	return;
}

void td2(void * i)

{
	while (1)
	{
		printf ("2\n");
		sleep (1);
	}

	return;
}

int
main(int argc,char *argv[],char *envp[])

{
	pthread_t	t1,t2;

	pthread_create(&t1, NULL, (void*)td1, NULL);
	pthread_create(&t2, NULL, (void*)td2, NULL);

	sleep (10);

	assert(0);

	return (0);
}

The follow is how to reproduce this issue:
arm-xxx-gcc -g -lpthread 1.c -o 1
copy 1.c and 1 to a arm board.
Goto this board.
ulimit -c 1800000
./1

# ./1
1
2
1
...
...
1
1: 1.c:37: main: Assertion `0' failed.
Aborted (core dumped)
Then you can get a core file.
gdb 1 core.xxx

Without the patch:
(gdb) info threads

  3 process 909  0x00000000 in ?? ()
  2 process 908  0x00000000 in ?? ()
* 1 process 907  0x4a6e2238 in raise () from /lib/libc.so.6

You can found that the pc of 909 and 908 is 0x00000000.

With the patch:
(gdb) info threads

  3 process 885  0x4a749974 in nanosleep () from /lib/libc.so.6
  2 process 884  0x4a749974 in nanosleep () from /lib/libc.so.6
* 1 process 883  0x4a6e2238 in raise () from /lib/libc.so.6

The pc of 885 and 884 is right.

Thanks,
Hui

author
#3 lore raw
Quoted 27 lines · Hui Zhu

Hi Amerigo,

Thanks for your reply.

Quoted 22 lines · Amerigo Wang

Hi, Hui.

Quoted 16 lines · Hui Zhu

Fix the multithread program core thread message error. The thread message of core file is generated in elf_dump_thread_status.  The register values is set by elf_core_copy_task_regs in this function.
static inline int elf_core_copy_task_regs(struct task_struct *t, elf_gregset_t* elfregs) {

      return ELF_CORE_COPY_TASK_REGS(t, elfregs);
      return 0;
}
If a arch doesn't define ELF_CORE_COPY_TASK_REGS, This function will do nothing.  Then the core file will not have the register message of thread.
So add elf_core_copy_regs to set regiser values if ELF_CORE_COPY_TASK_REGS doesn't define.

Quoted 3 lines
Quoted 1 line

You forgot your Signed-off-by line. :)

I need change it to Signed-off-by: Hui Zhu <[email protected]> Sorry about it.

Thanks,
Hui

#4 lore raw
In reply to Hui Zhu
Quoted 29 lines · Hui Zhu

Hi Amerigo,

Thanks for your reply.

Quoted 22 lines · Amerigo Wang

Hi, Hui.

Quoted 8 lines · Hui Zhu

Fix the multithread program core thread message error. The thread message of core file is generated in elf_dump_thread_status.  The register values is set by elf_core_copy_task_regs in this function.
static inline int elf_core_copy_task_regs(struct task_struct *t, elf_gregset_t* elfregs) {

Quoted 8 lines

      return ELF_CORE_COPY_TASK_REGS(t, elfregs);
      return 0;
}
If a arch doesn't define ELF_CORE_COPY_TASK_REGS, This function will do nothing.  Then the core file will not have the register message of thread.
So add elf_core_copy_regs to set regiser values if ELF_CORE_COPY_TASK_REGS doesn't define.

Quoted 1 line

You forgot your Signed-off-by line. :)

Quoted 8 lines
Quoted 4 lines

Hmmm, this patch looks sane for me. But could you please send us your test program? i.e. how did you test this?

I test this issue in a arm board. My test code is:

Thanks!

Hmm, this only affects the arch which neither has CORE_DUMP_USE_REGSET nor ELF_CORE_COPY_TASK_REGS, arm is one of them, but x86 not...

Could you please resend this patch with your favourite Signed-off-by and also put the reproduce steps below into your change log?

P.S. Add some Cc's for more reviews, don't drop them when you resend your patch.

Quoted 76 lines

#include <stdio.h>
#include <pthread.h>
#include <assert.h>

void td1(void * i)

{
	while (1)
	{
		printf ("1\n");
		sleep (1);
	}

	return;
}

void td2(void * i)

{
	while (1)
	{
		printf ("2\n");
		sleep (1);
	}

	return;
}

int
main(int argc,char *argv[],char *envp[])

{
	pthread_t	t1,t2;

	pthread_create(&t1, NULL, (void*)td1, NULL);
	pthread_create(&t2, NULL, (void*)td2, NULL);

	sleep (10);

	assert(0);

	return (0);
}

The follow is how to reproduce this issue:
arm-xxx-gcc -g -lpthread 1.c -o 1
copy 1.c and 1 to a arm board.
Goto this board.
ulimit -c 1800000
./1

# ./1
1
2
1
...
...
1
1: 1.c:37: main: Assertion `0' failed.
Aborted (core dumped)
Then you can get a core file.
gdb 1 core.xxx

Without the patch:
(gdb) info threads
3 process 909 0x00000000 in ?? ()
2 process 908 0x00000000 in ?? ()
* 1 process 907 0x4a6e2238 in raise () from /lib/libc.so.6 You can found that the pc of 909 and 908 is 0x00000000.

With the patch:
(gdb) info threads
3 process 885 0x4a749974 in nanosleep () from /lib/libc.so.6 2 process 884 0x4a749974 in nanosleep () from /lib/libc.so.6
* 1 process 883 0x4a6e2238 in raise () from /lib/libc.so.6 The pc of 885 and 884 is right.

Thanks,
Hui

author
#5 lore raw

Thanks for your help, Amerigo.

Hui

Fix the multithread program core thread message error. This issue just affect arch with neither has CORE_DUMP_USE_REGSET nor ELF_CORE_COPY_TASK_REGS, ARM is one of them.
The thread message of core file is generated in elf_dump_thread_status. The register values is set by elf_core_copy_task_regs in this function.
If a arch doesn't define ELF_CORE_COPY_TASK_REGS, The function elf_core_copy_task_regs will do nothing. Then the core file will not have the register message of thread.
So add elf_core_copy_regs to set regiser values if ELF_CORE_COPY_TASK_REGS doesn't define.
The following is how to reproduce this issue:
cat 1.c
#include <stdio.h>
#include <pthread.h>
#include <assert.h>

void td1(void * i)

{
       while (1)
       {
               printf ("1\n");
               sleep (1);
       }

       return;
}

void td2(void * i)

{
       while (1)
       {
               printf ("2\n");
               sleep (1);
       }

       return;
}

int
main(int argc,char *argv[],char *envp[])

{
       pthread_t       t1,t2;

       pthread_create(&t1, NULL, (void*)td1, NULL);
       pthread_create(&t2, NULL, (void*)td2, NULL);

       sleep (10);

       assert(0);

       return (0);
}

arm-xxx-gcc -g -lpthread 1.c -o 1
copy 1.c and 1 to a arm board.
Goto this board.
ulimit -c 1800000
./1

# ./1
1
2
1
...
...
1
1: 1.c:37: main: Assertion `0' failed.
Aborted (core dumped)
Then you can get a core file.
gdb 1 core.xxx
Without the patch:
(gdb) info threads
 3 process 909  0x00000000 in ?? ()
 2 process 908  0x00000000 in ?? ()
* 1 process 907  0x4a6e2238 in raise () from /lib/libc.so.6
You can found that the pc of 909 and 908 is 0x00000000.
With the patch:
(gdb) info threads
 3 process 885  0x4a749974 in nanosleep () from /lib/libc.so.6
 2 process 884  0x4a749974 in nanosleep () from /lib/libc.so.6
* 1 process 883  0x4a6e2238 in raise () from /lib/libc.so.6
The pc of 885 and 884 is right.
---
 elfcore.h |    2 ++
 1 file changed, 2 insertions(+)
include/linux/elfcore.h +0 -0
index 7605c5e..03ec167 100644
@@ -125,6 +125,8 @@ static inline int elf_core_copy_task_regs(struct

task_struct *t, elf_gregset_t*
#ifdef ELF_CORE_COPY_TASK_REGS

       return ELF_CORE_COPY_TASK_REGS(t, elfregs);
+#else
+       elf_core_copy_regs(elfregs, task_pt_regs(t));
 #endif
       return 0;

}

#6 lore raw
Quoted 1 line · Hui Zhu

Thanks for your help, Amerigo.

You're welcome.

Quoted 18 lines

Hui

---
elfcore.h | 2 ++

1 file changed, 2 insertions(+)
include/linux/elfcore.h +0 -0
index 7605c5e..03ec167 100644
@@ -125,6 +125,8 @@ static inline int elf_core_copy_task_regs(struct

task_struct *t, elf_gregset_t*
#ifdef ELF_CORE_COPY_TASK_REGS

      return ELF_CORE_COPY_TASK_REGS(t, elfregs);
include/linux/elfcore.h +2 -0
+#else
+       elf_core_copy_regs(elfregs, task_pt_regs(t));
Quoted 3 lines
#endif
      return 0;
}

Your email client eats tabs. :) Can you fix your email client or resend it with a tool like git send-email?

Thanks.

author
#7 lore raw
Quoted 8 lines
Quoted 7 lines

      return ELF_CORE_COPY_TASK_REGS(t, elfregs); +#else
+       elf_core_copy_regs(elfregs, task_pt_regs(t)); #endif
      return 0;
}

Quoted 5 lines

Your email client eats tabs. :) Can you fix your email client or resend it with a tool like git send-email?

Thanks.

Ah, sorry about it. I think the tabs was lost when I copy this code with wrong way.
I try this version with myself first. It looks ok. Please help me with it.

Thanks,
Hui

Fix the multithread program core thread message error. This issue just affect arch with neither has CORE_DUMP_USE_REGSET nor ELF_CORE_COPY_TASK_REGS, ARM is one of them.
The thread message of core file is generated in elf_dump_thread_status. The register values is set by elf_core_copy_task_regs in this function.
If a arch doesn't define ELF_CORE_COPY_TASK_REGS, The function elf_core_copy_task_regs will do nothing. Then the core file will not have the register message of thread.
So add elf_core_copy_regs to set regiser values if ELF_CORE_COPY_TASK_REGS doesn't define.
The following is how to reproduce this issue:
cat 1.c
#include <stdio.h>
#include <pthread.h>
#include <assert.h>

void td1(void * i)

{
	while (1)
	{
		printf ("1\n");
		sleep (1);
	}

	return;
}

void td2(void * i)

{
	while (1)
	{
		printf ("2\n");
		sleep (1);
	}

	return;
}

int
main(int argc,char *argv[],char *envp[])

{
	pthread_t	t1,t2;

	pthread_create(&t1, NULL, (void*)td1, NULL);
	pthread_create(&t2, NULL, (void*)td2, NULL);

	sleep (10);

	assert(0);

	return (0);
}

arm-xxx-gcc -g -lpthread 1.c -o 1
copy 1.c and 1 to a arm board.
Goto this board.
ulimit -c 1800000
./1

# ./1
1
2
1
...
...
1
1: 1.c:37: main: Assertion `0' failed.
Aborted (core dumped)
Then you can get a core file.
gdb 1 core.xxx
Without the patch:
(gdb) info threads
 3 process 909  0x00000000 in ?? ()
 2 process 908  0x00000000 in ?? ()
* 1 process 907  0x4a6e2238 in raise () from /lib/libc.so.6
You can found that the pc of 909 and 908 is 0x00000000.
With the patch:
(gdb) info threads
 3 process 885  0x4a749974 in nanosleep () from /lib/libc.so.6
 2 process 884  0x4a749974 in nanosleep () from /lib/libc.so.6
* 1 process 883  0x4a6e2238 in raise () from /lib/libc.so.6
The pc of 885 and 884 is right.
---
 elfcore.h |    2 ++
 1 file changed, 2 insertions(+)
include/linux/elfcore.h +0 -0
index 7605c5e..03ec167 100644
@@ -125,6 +125,8 @@ static inline int elf_core_copy_task_regs(struct

task_struct *t, elf_gregset_t*
#ifdef ELF_CORE_COPY_TASK_REGS

return ELF_CORE_COPY_TASK_REGS(t, elfregs);
+#else
+ elf_core_copy_regs(elfregs, task_pt_regs(t));
#endif
return 0;
}

#8 lore raw
In reply to Hui Zhu
Quoted 19 lines · On Wed, 1 Jul 2009 14:21:37 +0800 Hui Zhu <[email protected]> wrote:

Thanks for your help, Amerigo.

Hui

Fix the multithread program core thread message error. This issue just affect arch with neither has CORE_DUMP_USE_REGSET nor ELF_CORE_COPY_TASK_REGS, ARM is one of them.
The thread message of core file is generated in elf_dump_thread_status. The register values is set by elf_core_copy_task_regs in this function.
If a arch doesn't define ELF_CORE_COPY_TASK_REGS, The function elf_core_copy_task_regs will do nothing. Then the core file will not have the register message of thread.
So add elf_core_copy_regs to set regiser values if ELF_CORE_COPY_TASK_REGS doesn't define.
The following is how to reproduce this issue:

...

Quoted 12 lines

Without the patch:
(gdb) info threads
3 process 909 0x00000000 in ?? ()
2 process 908 0x00000000 in ?? ()
* 1 process 907 0x4a6e2238 in raise () from /lib/libc.so.6 You can found that the pc of 909 and 908 is 0x00000000. With the patch:
(gdb) info threads
3 process 885 0x4a749974 in nanosleep () from /lib/libc.so.6 2 process 884 0x4a749974 in nanosleep () from /lib/libc.so.6
* 1 process 883 0x4a6e2238 in raise () from /lib/libc.so.6 The pc of 885 and 884 is right.

I'm trying to work out if we should backport this fix into earlier kernels (2.6.30.x, 2.6.29.x, etc).

I'd have though that having gdb produce crap for all the threads would be fairly irritating to ARM developers and hence we should backport this. But perhaps it doens't affect many people, dunno.

What do poeple think?

#9 lore raw
Quoted 7 lines · Andrew Morton

I'd have though that having gdb produce crap for all the threads would be fairly irritating to ARM developers and hence we should backport this. But perhaps it doens't affect many people, dunno.

What do poeple think?

Not backporting would provide an incentive for people to step up to a more modern kernel. :)

One can always backport later if the situation really requires it. I say let it be.

b.g.

Signature · 2 lines
Bill Gatliff
[email protected]
#10 lore raw
In reply to Andrew Morton
Quoted 22 lines · Andrew Morton
Quoted 19 lines · On Wed, 1 Jul 2009 14:21:37 +0800 Hui Zhu <[email protected]> wrote:

Thanks for your help, Amerigo.

Hui

Fix the multithread program core thread message error. This issue just affect arch with neither has CORE_DUMP_USE_REGSET nor ELF_CORE_COPY_TASK_REGS, ARM is one of them.
The thread message of core file is generated in elf_dump_thread_status. The register values is set by elf_core_copy_task_regs in this function.
If a arch doesn't define ELF_CORE_COPY_TASK_REGS, The function elf_core_copy_task_regs will do nothing. Then the core file will not have the register message of thread.
So add elf_core_copy_regs to set regiser values if ELF_CORE_COPY_TASK_REGS doesn't define.
The following is how to reproduce this issue:

...

Quoted 13 lines
Quoted 4 lines

Without the patch:
(gdb) info threads
3 process 909 0x00000000 in ?? ()
2 process 908 0x00000000 in ?? ()

Quoted 8 lines

* 1 process 907 0x4a6e2238 in raise () from /lib/libc.so.6 You can found that the pc of 909 and 908 is 0x00000000. With the patch:
(gdb) info threads
3 process 885 0x4a749974 in nanosleep () from /lib/libc.so.6 2 process 884 0x4a749974 in nanosleep () from /lib/libc.so.6
* 1 process 883 0x4a6e2238 in raise () from /lib/libc.so.6 The pc of 885 and 884 is right.

Thanks for taking this.

Quoted 8 lines

I'm trying to work out if we should backport this fix into earlier kernels (2.6.30.x, 2.6.29.x, etc).

I'd have though that having gdb produce crap for all the threads would be fairly irritating to ARM developers and hence we should backport this. But perhaps it doens't affect many people, dunno.

What do poeple think?

This doesn't affect many platforms, only the platforms which has _neither_ CORE_DUMP_USE_REGSET nor ELF_CORE_COPY_TASK_REGS.

I haven't checked all, just x86 and arm, x86 doesn't, arm does.