Skip to contentSkip to conversation

ptracing a task from core_pattern pipe

DISCUSSION Daniel Walker 3 participants 11 messages Mar 16, 2013 – Mar 27, 2013

lore
Share & tools
lore
#0 lore raw

Hi,

I was writing an application to ptrace a process which is dumping core from inside the pipe application for core_pattern.

So for example you make core pattern equal to something like "|/bin/corepipe_app" then the kernel runs that app prior to actually killing the process that failed.

Before the pipe application runs it puts SIGKILL on the pending signal list for the failed application. However the application can't run.

This commit,

9899d11f654474d2d54ea52ceaa2a1f4db3abd68

seems to put a damper on ptracing the application at this point.

So I wanted to see what you think of all this.. Can we add an exception to this which would allow operations on a task which is dumping core, but still has SIGKILL pending. The other way would be to not add SIGKILL till after the pipe app runs.

As of right now I can PTRACE_ATTACH, but the operations all fail with -ESRCH .

Daniel

#1 lore raw

Hi Daniel,

Sorry, I can't understand your email...

Quoted 3 lines · Daniel Walker

I was writing an application to ptrace a process which is dumping core from inside the pipe application for core_pattern.

This was never possible. And never will, I think.

Quoted 3 lines

So for example you make core pattern equal to something like "|/bin/corepipe_app" then the kernel runs that app prior to actually killing the process that failed.

No, the dumper "kills" itself (but see below) and the starts /bin/corepipe_app.

Quoted 2 lines

Before the pipe application runs it puts SIGKILL on the pending signal list for the failed application.

if "it" means the dumper thread then "almost true". It kills other threads but not itself.

(Just in case, this was recently changed. After
coredump-ensure-that-sigkill-always-kills-the-dumping-thread.patch in -mm tree the dumper doesn't run in SIGNAL_GROUP_EXIT, but probably this doesn't matter)

Quoted 1 line

However the application can't run.

Which application? Both the dumper and corepipe_app can run...

Quoted 5 lines

This commit,

9899d11f654474d2d54ea52ceaa2a1f4db3abd68

seems to put a damper on ptracing the application at this point.

How can this commit make any difference? It should not.

Quoted 2 lines

So I wanted to see what you think of all this.. Can we add an exception to this which would allow operations on a task which is dumping core,

Which ptrace request you think should work at this stage? The coredumping task is dying, it can't report, say, signal or syscall. It can report nothing except PTRACE_EVENT_EXIT, but only after it closes the pipe.

Quoted 2 lines

but still has SIGKILL pending. The other way would be to not add SIGKILL till after the pipe app runs.

See above.

Quoted 2 lines

As of right now I can PTRACE_ATTACH, but the operations all fail with -ESRCH .

Sure, because the tracee doesn't (and shouldn't) stop, iow it doesn't report any event.

Could you explain what actually you are trying to do? And what exactly doesn't work as you expected?

Now that the coredump is killable (-mm patches), _perhaps_ we can, say, add PTRACE_EVENT_CORED_DUMPED reported after binfmt->core_dump(). Not sure this is what you need...

Oleg.

#2 lore raw
Quoted 5 lines · Oleg Nesterov
Quoted 3 lines · Daniel Walker

I was writing an application to ptrace a process which is dumping core from inside the pipe application for core_pattern.

Quoted 8 lines

This was never possible. And never will, I think.

Quoted 3 lines

So for example you make core pattern equal to something like "|/bin/corepipe_app" then the kernel runs that app prior to actually killing the process that failed.

No, the dumper "kills" itself (but see below) and the starts /bin/corepipe_app.

Not sure what you mean by "dumper" .. The thread that has failed (i.e. the thread which has seg faulted) is sleeping until the corepipe_app returns.

Quoted 6 lines
Quoted 2 lines

Before the pipe application runs it puts SIGKILL on the pending signal list for the failed application.

if "it" means the dumper thread then "almost true". It kills other threads but not itself.

"it" is in the kernel prior to spawning the corepipe_app , but I think it's the context of the thread which failed.. The SIGKILL is done in

Quoted 8 lines

(Just in case, this was recently changed. After
coredump-ensure-that-sigkill-always-kills-the-dumping-thread.patch in -mm tree the dumper doesn't run in SIGNAL_GROUP_EXIT, but probably this doesn't matter)

Quoted 1 line

However the application can't run.

Which application? Both the dumper and corepipe_app can run...

the "dumper" , assuming I know what you mean, is sleeping.. It can't run when corepipe_app runs. It wouldn't make sense because the core is getting saved at that point.

Quoted 7 lines
Quoted 5 lines

This commit,

9899d11f654474d2d54ea52ceaa2a1f4db3abd68

seems to put a damper on ptracing the application at this point.

How can this commit make any difference? It should not.

As I said there is a SIGKILL pending on the "dumper" thread, and your commit finds the SIGKILL pending.

Quoted 6 lines
Quoted 2 lines

So I wanted to see what you think of all this.. Can we add an exception to this which would allow operations on a task which is dumping core,

Which ptrace request you think should work at this stage? The coredumping task is dying, it can't report, say, signal or syscall. It can report nothing except PTRACE_EVENT_EXIT, but only after it closes the pipe.

It can give me it's registers, and allow me access to it's memory space. That's all I want realistically ..

Quoted 8 lines
Quoted 2 lines

but still has SIGKILL pending. The other way would be to not add SIGKILL till after the pipe app runs.

See above.

Quoted 2 lines

As of right now I can PTRACE_ATTACH, but the operations all fail with -ESRCH .

Quoted 7 lines

Sure, because the tracee doesn't (and shouldn't) stop, iow it doesn't report any event.

Could you explain what actually you are trying to do? And what exactly doesn't work as you expected?

I'm trying to get the "dumpers" registers and stack out when it fails.

Quoted 3 lines

Now that the coredump is killable (-mm patches), _perhaps_ we can, say, add PTRACE_EVENT_CORED_DUMPED reported after binfmt->core_dump(). Not sure this is what you need...

Not sure what this would accomplish .. I just want the processes registers and stack or access to all it's memory.

Daniel

#3 lore raw
Quoted 13 lines · Daniel Walker
Quoted 11 lines · Oleg Nesterov
Quoted 3 lines · Daniel Walker

I was writing an application to ptrace a process which is dumping core from inside the pipe application for core_pattern.

This was never possible. And never will, I think.

Quoted 3 lines

So for example you make core pattern equal to something like "|/bin/corepipe_app" then the kernel runs that app prior to actually killing the process that failed.

Quoted 6 lines
Quoted 2 lines

No, the dumper "kills" itself (but see below) and the starts /bin/corepipe_app.

Not sure what you mean by "dumper" .. The thread that has failed (i.e. the thread which has seg faulted)

Yes, and this is the thread which spawns corepipe_app and dumps the core.

Quoted 2 lines

is sleeping until the corepipe_app
returns.

Yes, but it dumps the core first. And to clarify, it sleeps until corepipe_app closes the pipe.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

Before the pipe application runs it puts SIGKILL on the pending signal list for the failed application.

if "it" means the dumper thread then "almost true". It kills other threads but not itself.

"it" is in the kernel prior to spawning the corepipe_app , but I think it's the context of the thread which failed.. The SIGKILL is done in

Can't understand... Yes it kills other threads before it starts the corepipe_app. To clarify, "kills" means it sends SIGKILL to other threads and wait until they all park in exit_mm().

Quoted 10 lines
Quoted 8 lines

(Just in case, this was recently changed. After
coredump-ensure-that-sigkill-always-kills-the-dumping-thread.patch in -mm tree the dumper doesn't run in SIGNAL_GROUP_EXIT, but probably this doesn't matter)

Quoted 1 line

However the application can't run.

Which application? Both the dumper and corepipe_app can run...

the "dumper" , assuming I know what you mean, is sleeping..

It sleeps only after it dumps the core. It only sleeps to ensure we do not close the write side prematurely.

Quoted 3 lines

It can't
run when corepipe_app runs. It wouldn't make sense because the core is getting saved at that point.

At this point it doesn't run, yes. But while it dumps the core they both run in parallel.

Quoted 9 lines
Quoted 7 lines
Quoted 5 lines

This commit,

9899d11f654474d2d54ea52ceaa2a1f4db3abd68

seems to put a damper on ptracing the application at this point.

How can this commit make any difference? It should not.

As I said there is a SIGKILL pending on the "dumper" thread,

As I said, there is no SIGKILL pending on the "dumper" thread. (unless it is actually killed of course).

Quoted 2 lines

and your
commit finds the SIGKILL pending.

Can't understand. It can find the pending SIGKILL, but only after ptrace() returns sucessfully and the tracee was stopped. And the dumper never stops.

Please explain what difference this patch makes in your testing.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

So I wanted to see what you think of all this.. Can we add an exception to this which would allow operations on a task which is dumping core,

Which ptrace request you think should work at this stage? The coredumping task is dying, it can't report, say, signal or syscall. It can report nothing except PTRACE_EVENT_EXIT, but only after it closes the pipe.

It can give me it's registers, and allow me access to it's memory space. That's all I want realistically ..

...

Quoted 1 line

I'm trying to get the "dumpers" registers and stack out when it fails.

Can't you read the generated core for that? And see below...

Quoted 6 lines
Quoted 3 lines

Now that the coredump is killable (-mm patches), _perhaps_ we can, say, add PTRACE_EVENT_CORED_DUMPED reported after binfmt->core_dump(). Not sure this is what you need...

Not sure what this would accomplish .. I just want the processes registers and stack or access to all it's memory.

Confused... why do you think PTRACE_EVENT_CORE_DUMPED reported after binfmt->core_dump() won't allow to do this?

Of course, this can't help to ptrace/inspect other threads, they are already (well, almost) dead at this point.

Oleg.

#4 lore raw
Quoted 5 lines · Oleg Nesterov
Quoted 5 lines
Quoted 5 lines

(Just in case, this was recently changed. After
coredump-ensure-that-sigkill-always-kills-the-dumping-thread.patch in -mm tree the dumper doesn't run in SIGNAL_GROUP_EXIT, but probably this doesn't matter)

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

However the application can't run.

Which application? Both the dumper and corepipe_app can run...

the "dumper" , assuming I know what you mean, is sleeping..

It sleeps only after it dumps the core. It only sleeps to ensure we do not close the write side prematurely.

The dumper thread is sleeping when the corepipe_app runs .. I ran "cat /proc/<pid>/status" from the corepipe_app .. It shows the dumper as sleeping.

Quoted 6 lines
Quoted 3 lines

It can't
run when corepipe_app runs. It wouldn't make sense because the core is getting saved at that point.

At this point it doesn't run, yes. But while it dumps the core they both run in parallel.

Not following you here.. If it's sleeping how can it be running too ?

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

This commit,

9899d11f654474d2d54ea52ceaa2a1f4db3abd68

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

seems to put a damper on ptracing the application at this point.

How can this commit make any difference? It should not.

As I said there is a SIGKILL pending on the "dumper" thread,

As I said, there is no SIGKILL pending on the "dumper" thread. (unless it is actually killed of course).

I pretty sure do_coredump()->core_wait()->zap_threads()->zap_process()
adds SIGKILL.. Assume that's not happening, why would ptrace give me -ESRCH, yet
/proc/<pid>/status would show me ptrace attached to the thread.

Quoted 7 lines
Quoted 2 lines

and your
commit finds the SIGKILL pending.

Can't understand. It can find the pending SIGKILL, but only after ptrace() returns sucessfully and the tracee was stopped. And the dumper never stops.

Please explain what difference this patch makes in your testing.

I haven't tested with or with out it, I've just read the code and it seems to be the only way I'm getting ESRCH back from ptrace..

For instance, I ptrace attach from inside the corepipe_app then try PTRACE_GETREGS and you get -ESRCH .

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

So I wanted to see what you think of all this.. Can we add an exception to this which would allow operations on a task which is dumping core,

Which ptrace request you think should work at this stage? The coredumping task is dying, it can't report, say, signal or syscall. It can report nothing except PTRACE_EVENT_EXIT, but only after it closes the pipe.

Quoted 8 lines
Quoted 2 lines

It can give me it's registers, and allow me access to it's memory space. That's all I want realistically ..

...

Quoted 1 line

I'm trying to get the "dumpers" registers and stack out when it fails.

Can't you read the generated core for that? And see below...

I'm not sure if it would accomplish what I need. I can't save the whole core, and I can't get memory to save large chunks of it.

ptrace after it crashes seems like a nice solution cause I can just examine the process already in memory.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

Now that the coredump is killable (-mm patches), _perhaps_ we can, say, add PTRACE_EVENT_CORED_DUMPED reported after binfmt->core_dump(). Not sure this is what you need...

Not sure what this would accomplish .. I just want the processes registers and stack or access to all it's memory.

Confused... why do you think PTRACE_EVENT_CORE_DUMPED reported after binfmt->core_dump() won't allow to do this?

Oh, I think I see what you mean. I would ptrace attach prior to the thread crashing , and get an event for when it crashes ?

Quoted 2 lines

Of course, this can't help to ptrace/inspect other threads, they are already (well, almost) dead at this point.

Ideally I would want to attach after it crashes, cause other wise I'd have to ptrace attach to a lot of threads (to monitor the whole system).

Daniel

#5 lore raw
Quoted 8 lines · Daniel Walker
Quoted 3 lines · Oleg Nesterov

It sleeps only after it dumps the core. It only sleeps to ensure we do not close the write side prematurely.

The dumper thread is sleeping when the corepipe_app runs .. I ran "cat /proc/<pid>/status" from the corepipe_app .. It shows the dumper as sleeping.

It runs whatever you see in /proc/status ;) Who do you think dumps the core? The dumper thread itself. But see below.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

It can't
run when corepipe_app runs. It wouldn't make sense because the core is getting saved at that point.

At this point it doesn't run, yes. But while it dumps the core they both run in parallel.

Not following you here.. If it's sleeping how can it be running too ?

See above. Once again, it dumps the core _then_ sleeps waiting pipe handler which should close the pipe.

And of course, you can see it sleeping in, say, pipe_write() if the buffer is full and the pipe handler doesn't read the data.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

As I said there is a SIGKILL pending on the "dumper" thread,

As I said, there is no SIGKILL pending on the "dumper" thread. (unless it is actually killed of course).

I pretty sure do_coredump()->core_wait()->zap_threads()->zap_process()
adds SIGKILL..

	static int zap_process(struct task_struct *start, int exit_code)
	{
		...

		do {
			task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK);
------------>			if (t != current && t->mm) {
				sigaddset(&t->pending.signal, SIGKILL);
				signal_wake_up(t, 1);
				nr++;
			}
		} while_each_thread(start, t);
	}
Quoted 2 lines

Assume that's not happening, why would ptrace give me -ESRCH, yet /proc/<pid>/status would show me ptrace attached to the thread.

And why do you think this should be explained by SIGKILL?

Quoted 4 lines
Quoted 1 line

Please explain what difference this patch makes in your testing.

I haven't tested with or with out it, I've just read the code and it seems to be the only way I'm getting ESRCH back from ptrace..

No,

Quoted 2 lines

For instance, I ptrace attach from inside the corepipe_app then try PTRACE_GETREGS and you get -ESRCH .

Sure. PTRACE_GETREGS and (almost) any other request can only succeed if the tracee is TASK_TRACED! I already told you that ptrace() doesn't and can't work exactly because the dumper never does ptrace_stop().

Quoted 11 lines
Quoted 8 lines
Quoted 2 lines

It can give me it's registers, and allow me access to it's memory space. That's all I want realistically ..

...

Quoted 1 line

I'm trying to get the "dumpers" registers and stack out when it fails.

Can't you read the generated core for that? And see below...

I'm not sure if it would accomplish what I need. I can't save the whole core, and I can't get memory to save large chunks of it.

Not sure I understand this part...

Quoted 2 lines

ptrace after it crashes seems like a nice solution cause I can just examine the process already in memory.

OK.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

Now that the coredump is killable (-mm patches), _perhaps_ we can, say, add PTRACE_EVENT_CORED_DUMPED reported after binfmt->core_dump(). Not sure this is what you need...

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Not sure what this would accomplish .. I just want the processes registers and stack or access to all it's memory.

Confused... why do you think PTRACE_EVENT_CORE_DUMPED reported after binfmt->core_dump() won't allow to do this?

Oh, I think I see what you mean. I would ptrace attach prior to the thread crashing ,

I don't understand what "prior to the thread crashing" means... the pipe hanlder is spawned after the task has already initiated the coredump... IOW, other threads are already killed and we are ready to actually dump the core.

Quoted 1 line

and get an event for when it crashes ?

And get an event after coredump_app closes the pipe. Assuming that you use PTRACE_SEIZE(PTRACE_O_CORE_DUMPED) rather that PTRACE_ATTACH. And assuming you do this before you close the pipe, otherwise it can exit before you do PTRACE_SEIZE.

Quoted 5 lines
Quoted 2 lines

Of course, this can't help to ptrace/inspect other threads, they are already (well, almost) dead at this point.

Ideally I would want to attach after it crashes, cause other wise I'd have to ptrace attach to a lot of threads (to monitor the whole system).

See above. You do not need to attach in advance.

But once again, you can't attach the sub-threads, they are already dead when coredump_app is called. PTRACE_ATTACH will work but this can help, a sub-thread will never report any event and PF_EXITING is already set.

Oleg.

#6 lore raw
Quoted 4 lines · Oleg Nesterov
Quoted 2 lines

Assume that's not happening, why would ptrace give me -ESRCH, yet /proc/<pid>/status would show me ptrace attached to the thread.

And why do you think this should be explained by SIGKILL?

It's an assumption, if I knew before you would be getting a patch instead of an email.

Quoted 5 lines
Quoted 4 lines
Quoted 1 line

Please explain what difference this patch makes in your testing.

I haven't tested with or with out it, I've just read the code and it seems to be the only way I'm getting ESRCH back from ptrace..

Quoted 8 lines

No,

Quoted 2 lines

For instance, I ptrace attach from inside the corepipe_app then try PTRACE_GETREGS and you get -ESRCH .

Sure. PTRACE_GETREGS and (almost) any other request can only succeed if the tracee is TASK_TRACED! I already told you that ptrace() doesn't and can't work exactly because the dumper never does ptrace_stop().

When does ptrace_stop run ?

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

It can give me it's registers, and allow me access to it's memory space. That's all I want realistically ..

...

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

I'm trying to get the "dumpers" registers and stack out when it fails.

Can't you read the generated core for that? And see below...

I'm not sure if it would accomplish what I need. I can't save the whole core, and I can't get memory to save large chunks of it.

Not sure I understand this part...

The above is regarding the situation which I'm running my corepipe_app , i.e. my system doesn't have a disk to save a core file for parsing.

Quoted 8 lines
Quoted 3 lines

Oh, I think I see what you mean. I would ptrace attach prior to the thread crashing ,

I don't understand what "prior to the thread crashing" means... the pipe hanlder is spawned after the task has already initiated the coredump... IOW, other threads are already killed and we are ready to actually dump the core.

I can't attach to the thread after it's crashed, since I get ESRCH in the corepipe_app for every operation, so that suggests I'd need to attach prior to when it crashes.

Quoted 6 lines
Quoted 1 line

and get an event for when it crashes ?

And get an event after coredump_app closes the pipe. Assuming that you use PTRACE_SEIZE(PTRACE_O_CORE_DUMPED) rather that PTRACE_ATTACH. And assuming you do this before you close the pipe, otherwise it can exit before you do PTRACE_SEIZE.

So corepipe_app would PTRACE_SEIZE then close the pipe but continue running ?

Quoted 11 lines
Quoted 5 lines
Quoted 2 lines

Of course, this can't help to ptrace/inspect other threads, they are already (well, almost) dead at this point.

Ideally I would want to attach after it crashes, cause other wise I'd have to ptrace attach to a lot of threads (to monitor the whole system).

See above. You do not need to attach in advance.

But once again, you can't attach the sub-threads, they are already dead when coredump_app is called. PTRACE_ATTACH will work but this can help, a sub-thread will never report any event and PF_EXITING is already set.

Ok ..

Daniel

#7 lore raw
Quoted 11 lines · Daniel Walker
Quoted 7 lines · Oleg Nesterov
Quoted 3 lines

For instance, I ptrace attach from inside the corepipe_app then try PTRACE_GETREGS and you get -ESRCH .

Sure. PTRACE_GETREGS and (almost) any other request can only succeed if the tracee is TASK_TRACED! I already told you that ptrace() doesn't and can't work exactly because the dumper never does ptrace_stop().

When does ptrace_stop run ?

When the tracee stops in TASK_TRACED for debugger, after that the debugger can do ptrace(GETREGS/whatever).

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I'm not sure if it would accomplish what I need. I can't save the whole core, and I can't get memory to save large chunks of it.

Not sure I understand this part...

The above is regarding the situation which I'm running my corepipe_app , i.e. my system doesn't have a disk to save a core file for parsing.

Can't you process the data inplace? You do not need to save it to disk.

I understand, this is probably not very convenient, but any new kernel feature should be justified. And let me repeat, even if we add PTRACE_EVENT_COREDUMPED you won't be able to ptrace sub-threads, so this feature doesn't look very nice.

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

Oh, I think I see what you mean. I would ptrace attach prior to the thread crashing ,

I don't understand what "prior to the thread crashing" means... the pipe hanlder is spawned after the task has already initiated the coredump... IOW, other threads are already killed and we are ready to actually dump the core.

I can't attach to the thread after it's crashed,

Daniel, you can, but:

Quoted 2 lines

since I get ESRCH in
the corepipe_app for every operation,

This is another thing, and I already explained many times why this happens.

Quoted 2 lines

so that suggests I'd need to attach
prior to when it crashes.

If you can attach prior to when it crashes then I do not understand why do you need the piped coredump at all. You can do everything you need after the tracee reports SEGFAULT or another sig_kernel_coredump() signal.

Quoted 6 lines
Quoted 4 lines

And get an event after coredump_app closes the pipe. Assuming that you use PTRACE_SEIZE(PTRACE_O_CORE_DUMPED) rather that PTRACE_ATTACH. And assuming you do this before you close the pipe, otherwise it can exit before you do PTRACE_SEIZE.

So corepipe_app would PTRACE_SEIZE then close the pipe but continue running ?

Well, yes... But I am not sure I understand the question...

What this "but continue running" means? Of course corepipe_app can run after it closes the pipe.

Daniel, I feel you misunderstand something (or perhaps it is me), but I can't understand what exactly you do not understand, sorry ;) I will be happy to help if you ask the more "explicit" questions.

Oleg.

#8 lore raw
Quoted 4 lines · Oleg Nesterov
Quoted 2 lines

The above is regarding the situation which I'm running my corepipe_app , i.e. my system doesn't have a disk to save a core file for parsing.

Can't you process the data inplace? You do not need to save it to disk.

Quoted 1 line · Daniel
Quoted 1 line

I'm trying to get the "dumpers" registers and stack out when it fails.

Registers would be easy'ish to get from coredump:
they are contained in note sections which are at the beginning of the coredump. You can implement necessary parsing without too much pain.

Getting at stack would be harder.

But by asking kernel to allow you to poke around dead task's address space with ptrace() calls you just shift difficulty away from you (today you need to implement in-memory ELF parsing) to kernel people (they will need to implement *and support* ptracing of coredumping tasks).

This is somewhat unfair, considering that coredumping code in kernel is already a source of many complications, and that kernel-side coding is harder than userspace.

I think you are lucky that ptrace attach even *works* on coredumping task. No documentation ever guaranteed such a thing.

Did you try whether process_vm_readv() works on coredumping task? If it is, then you can get at dying process' address space that way.

Signature · 1 line
vda
#9 lore raw
Quoted 8 lines · Denys Vlasenko
Quoted 4 lines · Oleg Nesterov
Quoted 2 lines

The above is regarding the situation which I'm running my corepipe_app , i.e. my system doesn't have a disk to save a core file for parsing.

Can't you process the data inplace? You do not need to save it to disk.

Daniel said:

Quoted 8 lines
Quoted 1 line
Quoted 1 line

I'm trying to get the "dumpers" registers and stack out when it fails.

Registers would be easy'ish to get from coredump:
they are contained in note sections which are at the beginning of the coredump. You can implement necessary parsing without too much pain.

Getting at stack would be harder.

There exists /proc/<pid>/mem and /proc/<pid>/maps on these tasks. If those don't work then that's a straight up defect..

Quoted 6 lines

But by asking kernel to allow you to poke around dead task's address space with ptrace() calls you just shift difficulty away from you (today you need to implement in-memory ELF parsing) to kernel people (they will need to implement *and support* ptracing of coredumping tasks).

Quoted 6 lines

This is somewhat unfair, considering that coredumping code in kernel is already a source of many complications, and that kernel-side coding is harder than userspace.

I think you are lucky that ptrace attach even *works* on coredumping task. No documentation ever guaranteed such a thing.

There not much different from userspace between a task running, and one dumping.. I think it should be the inverse, ptrace either needs to work or the special case needs to be documented that it doesn't work.

However, I do agree that you can parse the core file..

Daniel

#10 lore raw
Quoted 31 lines · Daniel Walker
Quoted 8 lines · Denys Vlasenko
Quoted 4 lines · Oleg Nesterov
Quoted 2 lines

The above is regarding the situation which I'm running my corepipe_app , i.e. my system doesn't have a disk to save a core file for parsing.

Can't you process the data inplace? You do not need to save it to disk.

Daniel said:

Quoted 8 lines
Quoted 1 line
Quoted 1 line

I'm trying to get the "dumpers" registers and stack out when it fails.

Registers would be easy'ish to get from coredump:
they are contained in note sections which are at the beginning of the coredump. You can implement necessary parsing without too much pain.

Getting at stack would be harder.

There exists /proc/<pid>/mem and /proc/<pid>/maps on these tasks. If those don't work then that's a straight up defect..

Quoted 10 lines

But by asking kernel to allow you to poke around dead task's address space with ptrace() calls you just shift difficulty away from you (today you need to implement in-memory ELF parsing) to kernel people (they will need to implement *and support* ptracing of coredumping tasks).

This is somewhat unfair, considering that coredumping code in kernel is already a source of many complications, and that kernel-side coding is harder than userspace.

Quoted 5 lines
Quoted 2 lines

I think you are lucky that ptrace attach even *works* on coredumping task. No documentation ever guaranteed such a thing.

There not much different from userspace between a task running, and one dumping..

As I see it, dumping task is past the point where it can enter ptrace-stops.

It's like asking to ptrace a task which already entered the kernel via exit(0) syscall and complaining that "it doesn't work". Of course it does not: a ptrace-stop can happen only after syscall returns to userspace, and exit() doesn't return.

Coredumping is similar: the task is in kernelspace and it won't ever return to userspace.

Signature · 1 line
vda