[Mono-list] JIT patch for stabs debugging

Martin Baulig martin@gnome.org
10 Mar 2002 13:45:49 +0100


Paolo Molaro <lupus@ximian.com> writes:

> On 03/10/02 Martin Baulig wrote:
> > 1.) Puts a NOP instruction at the start of every method.
> > 
> >     If you use `mono --debug Something', this buts a breakpoint
> >     instruction (INT 3) at the start of "Something" - which means
> >     that the address of Something's first instruction changes, but
> >     this address is already hard-coded into the stabs file.
> > 
> >     So without the NOP instructions you need to recreate your stabs
> >     symbol files each time you want to run mono with different --debug
> >     arguments.
> 
> No, this is wrong: if you restart mono, all the infos in the stab file
> are wrong. It may have happened that in two runs the same method was
> assigned the same address by malloc, but you can't rely on it:-)
> I don't know if a recent gdb allows to unload a debug object, if it
> still doesn't, you need to quit and restart gdb as well (and recompile
> the stabs each time you start mono).

Sure, that's right. The problem is that SIGABRT usually is normally a
deadly signal for a process - so you can't run "mono --stabs --debug"
in a shell. On the other hand, running it in gdb to create the stabs
files is very inconvenient since you must hit enter each time it
reaches a breakpoint.

In most situations, running mono several times with the same stabs
file should work fine as long as the program flow stays the same - for
instance, you have a test case which takes no user input and always
produces the same output. There, being able to restart the program
with different --debug arguments can be very useful.

> > 2.) Uses correct line numbers in the stabs file.
> > 
> >     In mono_debug_add_method(), `t->cli_add' is a bytecode offset, but
> >     not a line number in the .il file.
> 
> Thanks for fixing this: I ran out of time to properly implement this
> when I added support for debugging and since stabs format allows lines
> up to 2^16 I planned to switch to the dwarf debug format anyway
> (plus, there is an actual specification for dwarf, <grin>).

Oooops, really ? There are more than 2^16 lines in corlib.il, but I
only debugged things around line 40774 so far.

> > @@ -201,14 +228,16 @@
> >  mono_debug_add_method (MonoDebugHandle* debug, MonoFlowGraph *cfg)
> >  {
> >  	char *name;
> > -	int line = 0;
> > -	int i;
> > +	int line = 0, line_index = 0;
> > +	int i, print;
> >  	MonoMethod *method = cfg->method;
> >  	MonoClass *klass = method->klass;
> >  	MonoMethodSignature *sig = method->signature;
> >  	char **names = g_new (char*, sig->param_count);
> >  	AssemblyDebugInfo* info = mono_debug_open_ass (debug, klass->image);
> >  
> > +	print = !strcmp (method->name, "Parse") || !strcmp (method->name, "Main");
> > +
> ^^^^^^^^^^^^^^^^^^^^^^^
> Leftover from debugging?

Yes, removed.

> > --- x86.brg	2002/03/08 06:08:46	1.92
> > +++ x86.brg	2002/03/09 21:48:16
> > @@ -816,7 +816,7 @@
> >  	if (tree->left->reg1 != X86_EAX)
> >  		x86_mov_reg_reg (s->code, X86_EAX, tree->left->reg1, 4);
> >  
> > -	x86_cdq (s->code);
> > +	x86_mov_reg_imm (s->code, X86_EDX, 0);
> >  	x86_div_reg (s->code, tree->right->reg1, FALSE);
> >  
> >  	mono_assert (tree->reg1 == X86_EAX &&
> 
> Use xor %edx, %edx, there.

There is no x86_xor(), but x86_mov_reg_imm() already emits a XOR if the argument is zero.

Btw., this shouldn't be in the diff, it's another patch which Dietmar already approved.

-- 
Martin Baulig
martin@gnome.org