hi friends

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using Microsoft.Samples.Debugging.MdbgEngine;
using System.IO;
using System.Xml;
using Microsoft.Samples.Debugging.CorDebug.NativeApi;
using System.Text.RegularExpressions;


namespace callstcak
{
class Program
{
// Skip past fake attach events.
static void DrainAttach(MDbgEngine debugger, MDbgProcess proc)
{
bool fOldStatus = debugger.Options.StopOnNewThread;
debugger.Options.StopOnNewThread = false; // skip while waiting for AttachComplete

proc.Go().WaitOne();
Debug.Assert(proc.StopReason is AttachCompleteStopReason);

debugger.Options.StopOnNewThread = true; // needed for attach= true; // needed for attach

// Drain the rest of the thread create events.
while (proc.CorProcess.HasQueuedCallbacks(null))
{
proc.Go().WaitOne(); ------------------------------------------------------------->>>>>>>>>>>herethis programm go under indefinie waite ...
Debug.Assert(proc.StopReason is ThreadCreatedStopReason);
}

debugger.Options.StopOnNewThread = fOldStatus;
}


static void Main(string[] args)
{
int pid;//= int.Parse(args[0]);
Process[] pr = Process.GetProcesses();
foreach (Process p in pr)
{
if (p.ProcessName == "NmcsBootstrapLoader")
{


MDbgEngine debugger = new MDbgEngine();

MDbgProcess proc = null;
try
{

pid = int.Parse(p.Id.ToString());
proc = debugger.Attach(pid);
DrainAttach(debugger, proc);
Console.WriteLine("i m here for call stack");
MDbgThreadCollection tc = proc.Threads;

Console.WriteLine("Attached to pid:{0}", pid);
foreach (MDbgThread t in tc)
{
Console.WriteLine("Callstack for Thread {0}", t.Id.ToString());

foreach (MDbgFrame f in t.Frames)
{
Console.WriteLine(" call satck:: " + f);
}


}

}
finally
{
if (proc != null) { proc.Detach().WaitOne(); }
}


}

}
}
}
}

please friends have look on my code . my programm go under infinite wiat , i mention where its go in my code .

i come acroos many threads here which facing or mentioning same issue but i m little bit doubtfull bcoz non of the soltion is working in my code .

so anyone there who can tell me wats eaxctly wrong there in my code . or i need to study any othr material ..

any guidline or solution is most welcome ..

thans in advance


regards
aniruddha .

  • Moved bynobugzMVPMonday, July 27, 2009 10:27 AM (From:.NET Base Class Library)
  •  

Answers

  • Tuesday, July 28, 2009 5:04 AMNoah Falk - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    You shouldn't actually need that call to DrainAttach(debugger, proc)... in the sample code mdbg should alreadybe doing that work for you by not triggering the AttachComplete until the event queue has been drained. Try just calling proc.Go().WaitOne() instead of DrainAttach().

    As for your infinite wait, I can only assume it is because the queue has events that aren't shell-stopping events. A shell stopping event will call MdbgProcess.InternalSignalRuntimeIsStopped which is what signals the WaitHandle you are blocked on. If you look at the methods that end with EventHandler in MdbgProcess you will see that not all of them do this however. So your code is probably continuing, expecting the shell to stop again, but the events which were left weren't shell-stopping so you never stopped.

    Hope that helps,
    -Noah

All Replies

  • Monday, July 27, 2009 4:26 AManiruddha84 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    here NmcsBootstrapLoader is my exe,,..

    i m showing call stack for it

    all other exe its working fine . for this one exe this code goes in to infinite wait