[Mono-dev] runtime dbg library API proposal/impl

Martin Baulig martin at ximian.com
Thu Dec 6 08:24:27 EST 2007


On Thu, 2007-12-06 at 11:53 +0100, Paolo Molaro wrote:
> On 12/05/07 Martin Baulig wrote:
> > There is just one important thing to keep in mind:
> > 
> > > public TargetAddress MonoClassGetMonoImage (ITargetMemoryAccess memory,
> > >                                             TargetAddress klass)
> > >                 {
> > >                         IntPtr image = mono_debugger_support_mono_class_get_image (
> > >                                 memory.ReadMemory, klass.Address);
> > >                         return new TargetAddress (image);
> > >                 }
> > 
> > You have to use the `memory' instance to read memory (we may add other
> > methods to it if necessary) - but you do not "own" it.  It is absolutely
> > forbidden to store this anywhere or use it after the method returned
> > control back to the debugger.
> 
> Can you elaborate why you have this requirement?

That's a little bit incorrect:

> When you're debugging a target process it's either alive and you can use
> ptrace or access /proc/pid/mem or it's dead and you access the core
> file: why would you want to switch to one mechanism or the other on the
> fly?

Correct is:

"When you're debugging a target process it's either alive _and stopped_
and you can use ... or it's dead and you access the file, or it's
running and you can't do any of these."

That's the reason why you're not allowed to store the `memory' instance
anywhere: the corresponding thread is guaranteed to be stopped at the
time of the call, but it may be resumed by the debugger immediately
after returning from the call.

Also, ptrace() operates on threads, not processes.

I saw that you tried to use ptrace() on the process id or
access /proc/<process-id>/mem - this is wrong since the process id is in
fact just a thread for the linux kernel - so you would always read from
the main thread, and there is no guarantee that it will be stopped.

Instead, the debugger needs to give your API some kind of
`target access' / `thread' pointer and only this single thread is
guaranteed to be stopped at the point of the call.

-- 
Martin Baulig - martin at novell.com
Novell GmbH, Düsseldorf
GF: Volker Smid, Djamel Souici; HRB 21108 (AG Düsseldorf)





More information about the Mono-devel-list mailing list