[Mono-devel-list] monodebugger - Inserting breakpoints in a method that has been JITted
writetorex at rediffmail.com
Thu Jan 20 08:09:47 EST 2005
Thanks for the response.
For example, if i want to set a breakpoint at ILOffset 5 for a managed method, is the following true?
Step1. I find the memory address corresponding to an ILOffset 6 for the managed method. I do this in mono_arch_output_basic_block. Let's assume no JIT optimizations.
Step2. I write a software breakpoint opcode at the memory address that i found in Step 1.
Can a software breakpoint be written to replace any opcode? or are there rules on where software breakpoints are allowed?
I tried the following on a simple C# HelloWorld application with just two lines of code
Console.WriteLine ("Hello World 1");
Console.WriteLine ("Hello World 2");
1. Remember/Store the memory address corresponding to the ILOffset of the sourceline that has the "WriteLine" call. Did this in mono_arch_output_basic_block
2. After the method "main" has been JITted replace the value at memory address in step 1 with a 0xCC. (E8 is the original opcode at this address)
3. Allow the method to run
4. Method hits the software breakpoint and generates a breakpoint exception
5. An UnhandledExceptionFilter that is registered gets called (I'm on windows)
6. In this filter function replace the 0xCC with the original instruction which is E8.
7. Resume execution of main
The result is that the string "Hello World 1" gets printed but the second string "Hello World 2" does not get printed and application just finishes execution withut any obvious indications of a crash.
Then i tried the following
1. Forced a software breakpoint to be inserted at the beginning of the managed method "main". Did this in "mono_method_to_ir" using the CEE_BREAK code that is already in there.
2.Now when main executes & the breakpoint is hit, control reaches the unhandledexceptionfilter function where i just do a Eip++.
3.Resume execution of main
The result is that the strings "Hello World 1" & "Hello World 2" get printed.
That leads me to believe that a breakpoint opcode should not be placed at certain places in emitted code. Is that right?
Thanks! Sorry about the long email.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Mono-devel-list