Example #1
0
        // TODO: options for how the stack should be displayed

        protected override void ProcessRecord()
        {
            if (null != Thread)
            {
                foreach (var t in Thread)
                {
                    if (null != t)
                    {
                        WriteObject(t.GetStackWithMaxFrames(MaxFrameCount));
                    }
                    else
                    {
                        SafeWriteWarning("Null entry in -Thread parameter array.");
                    }
                }

                return;
            }

            IList <string> paths;

            if ((null == ContextPath) || (0 == ContextPath.Length))
            {
                PathInfo pi = this.CurrentProviderLocation(DbgProvider.ProviderId);
                paths = new string[] { pi.ProviderPath };
            }
            else
            {
                ProviderInfo pi;
                var          tmpList = new List <string>();
                foreach (string p in ContextPath)
                {
                    tmpList.AddRange(SessionState.Path.GetResolvedProviderPathFromPSPath(p, out pi));
                }

                paths = tmpList;
            }

            foreach (string path in paths)
            {
                DbgStackInfo stack = DbgProvider.GetStackInfoForPath(path, MaxFrameCount);
                if (null != stack)
                {
                    // TODO: Make sure the formatting is working such that we are not waiting
                    // for the entire stack to be calculated before seeing any output. (Could
                    // a test be written for that?)
                    SafeWriteObject(stack);
                }
                else
                {
                    var ioe = new InvalidOperationException(Util.Sprintf("No stack context for path: {0}", path));
                    try { throw ioe; } catch (Exception) { }   // give it a stack

                    // TODO: Need a "no stack context exception" or something
                    WriteError(ioe,
                               "NoStackContext",
                               ErrorCategory.InvalidOperation,
                               path);
                }
            } // end foreach( path )
        }     // end ProcessRecord()