debugger blues

Marco Leise via Digitalmars-d digitalmars-d at puremagic.com
Sun Mar 27 08:40:47 PDT 2016


Am Fri, 25 Mar 2016 09:00:06 +0000
schrieb cy <dlang at verge.info.tm>:

> No, the stack trace is the hierarchy of functions that are 
> currently calling each other. I meant the functions that had been 
> called previously, even the ones that have returned.

Is it just me? I've never heard of a programming environment,
let alone a system programming language providing that
information. While I understand, why the solidity of DWARF
debug information is important, this seems to me like a pie in
the sky idea similar to the pony. I guess the front-end would
have to instrument code for that and the debugger is out of
the picture, but you should detail that in a DIP. It does
sound like an interesting idea to supplement existing
instrumentation for profiling in DMD.

> > I'm afraid to say that only you can improve your own printf 
> > messages.
> 
> Or, write a print function that actually puts spaces between the 
> arguments, or write a function that adds the file and line so you 
> know where the statement was written and don't have to go hunting 
> for it. Or std.experimental.logger or whatever. I'd use 
> std.experimental.logger except it DOESN'T LET YOU PUT SPACES 
> BETWEEN THE ARGUMENTS >:(
> 
> (can you tell I programmed a lot in python?)

Yes, alright, but you can probably tell that std.logger was
modeled after the existing formatting functionality of
std.file (e.g. writefln) and that was modeled after printf, so
to put spaces between the arguments you just add them to the
formatting string. Just use format strings, case solved.
Surely we can look at Python style spaces between arguments,
but "DOESN'T LET YOU PUT SPACES BETWEEN THE ARGUMENTS" is just
silly and factually wrong.

> > Use @disable this(this); in your structs.
> 
> Well, obviously. But I meant a way to specify it in the function 
> I'm writing. Like @nocopy or @move or something.

If you ask for a *guarantee* of no copy on struct return, then
you are right. In praxis, the memory for the return value is
allocated on the caller's stack and the callee writes directly
into it. No copy or copy constructor call is performed. In
addition most (all?) ABIs allow structs of 1 or 2 machine words
to be returned in registers (i.e. EAX:EDX on x86).

Proof:

BigStruct returnsBigStruct()
{
	BigStruct ret = returnsBigStructToo();
	ret.data[0] = 42;
	return ret;
}


BigStruct returnsBigStructToo()
{
	import std.range;
	BigStruct ret = BigStruct( iota(20).array[0 .. 20] );
	return ret;
}

struct BigStruct
{
	int[20] data;
	
	this(this)
	{
		import std.stdio;
		writeln("I'm typically not called at all.");
	}
}

void main()
{
	import std.stdio;
	immutable bigStruct = returnsBigStruct();
	writeln( bigStruct.data );
}

-- 
Marco



More information about the Digitalmars-d mailing list