code-debug icon indicating copy to clipboard operation
code-debug copied to clipboard

Add multi-process support

Open LeszekSwirski opened this issue 7 years ago • 6 comments

Add support for debugging applications which fork, gated behind a new configuration flag. GDB only.

LeszekSwirski avatar Feb 21 '18 17:02 LeszekSwirski

not sure if it happens because of this PR but the continue button doesn't show it anymore when it continues on the normal mode + the UI doesn't update when the location changes (you need to click it again to update), maybe because of the new thread names now?

This PR functionality seems to be broken for me too: if I step over the fork call it just continues running and never breaks again and doesn't show a callstack, if I continue over a fork it shows the PIDs on the callstack but it doesn't show it continuing and it never breaks again too https://wfr.moe/fCWBOz.png

WebFreak001 avatar Feb 21 '18 17:02 WebFreak001

Yeah, I should have said that this is very WIP, very experimental, I more wanted to share the general idea. There's definitely more work to be done.

One of the big differences with the single process mode is that I use non-stop mode, i.e. only one thread is paused after a break point, not all of them. Would that explain the behaviour you're seeing? Could you share the test program?

LeszekSwirski avatar Feb 21 '18 21:02 LeszekSwirski

ah yeah that could be the reason.

Here the source: (compile with dmd -g app.d)

import std.stdio;
import core.thread;
import core.sys.posix.unistd;
import std.process;

struct S
{
	int a;
	long b;
	string c;
	T* f;
}

struct T
{
	byte d;
	char e;
	T* child;
}

void main(string[] args)
{
	writeln("Waiting 10s for attach");
	Thread.sleep(10.seconds);
	foreach (key, value; environment.toAA)
		writeln(key, " = ", value);
	stdout.flush();

	for (int i = 0; i < 3; i++)
	{
		writeln(i);
		stdout.flush();
		Thread.sleep(1.seconds);
	}

	if (args.length > 1 && args[1] == "fork")
		fork();
	else if (args.length == 1 || args[1] != "single")
		new Thread(&secondThread).start();

	write("No newline!");
	stdout.flush();
	int count = 5;

	for (; count < 20; count++)
	{
		S s;
		s.f = new T();
		s.f.child = new T();
		s.f.child.d = 4;
		s.a = count;
	}

	writeln("Got Arguments: ", args);
}

void secondThread()
{
	for (int i = 0; i < 10; i++)
	{
		writeln("Multithreaded ", i);
		stdout.flush();
		Thread.sleep(1.seconds);
	}
}

Execute it with arguments = fork in the debugger extension to make it fork instead of multithread, add some breakpoints here and there. Here is a binary if you are on linux: app.zip

I mean that's not the way how you would call fork in an actual application but it does something which should be debuggable.

WebFreak001 avatar Feb 21 '18 21:02 WebFreak001

@LeszekSwirski that's an interesting issue - can you update the conflicting files and, if you still see it as a WIP mark it as draft?

GitMensch avatar Jul 15 '20 06:07 GitMensch

I've rebased the PR and marked it as draft, I don't currently have the cycles to investigate this any further though.

LeszekSwirski avatar Jul 20 '20 10:07 LeszekSwirski

Thank you @LeszekSwirski for the update, so it is now up to @WebFreak001 or others to take it up.

GitMensch avatar Jul 20 '20 10:07 GitMensch