} // end constructor protected override void ProcessRecord() { base.ProcessRecord(); if (String.IsNullOrEmpty(Name)) { Name = "*"; } else if (Name.IndexOf('!') >= 0) { WriteWarning("Locals symbols shouldn't have a '!' in them."); } // // I would love to use the DbgHelp API to enumerate locals directly. Unfortunately, // // the SYMBOL_INFO information for locals will take a LOT of work to interpret (thanks // // to "register relative", etc.). For now, we'll use the dbgeng API. // foreach( var si in DbgHelp.EnumSymbols( Debugger.DebuggerInterface, // 0, // modBase of 0 and no '!' in the mask means we're looking for locals/params // Name, // CancelTS.Token ) ) // { // //WriteObject( si ); // WriteObject( new DbgPublicSymbol( Debugger, si, Debugger.GetCurrentProcess() ) ); // } // //throw new NotImplementedException(); // TODO: this should probably throw if we don't have private symbols DbgSymbolGroup dsg = new DbgSymbolGroup(Debugger, Scope); var pat = new WildcardPattern(Name, WildcardOptions.CultureInvariant | WildcardOptions.IgnoreCase); foreach (var sym in dsg.Items) { if (null == sym.Parent) // we only write out the top-level symbols { if (pat.IsMatch(sym.Name)) { WriteObject(sym); } } } } // end ProcessRecord()
private void _DumpByName() { // TODO: this should probably throw if we don't have private symbols DbgSymbolGroup dsg = new DbgSymbolGroup(Debugger, DEBUG_SCOPE_GROUP.ALL); if (String.IsNullOrEmpty(Name)) { Name = "*"; var pat = new WildcardPattern(Name, WildcardOptions.CultureInvariant | WildcardOptions.IgnoreCase); foreach (var sym in dsg.Items) { if (null == sym.Parent) // we only write out the top-level symbols { if (pat.IsMatch(sym.Name)) { WriteObject(_GetValue(sym)); } } } } else { var tokens = Name.Split('.'); string startName = tokens[0]; IList <DbgSymbol> rootSyms; if (startName.IndexOf('!') >= 0) { // Global(s). rootSyms = Debugger.FindSymbol_Search(startName, Category, CancelTS.Token).ToList(); } else { // Local(s). WildcardPattern pat = new WildcardPattern(startName); rootSyms = dsg.Items.Where((s) => pat.IsMatch(s.Name)).Cast <DbgSymbol>().ToList(); } if ((null == rootSyms) || (0 == rootSyms.Count)) { // TODO: Some sort of "symbol not found" exception WriteError(new ArgumentException(Util.Sprintf("Symbol \"{0}\" not found.", startName)), "SymbolNotFound", ErrorCategory.ObjectNotFound, startName); return; } foreach (DbgSymbol rootSym in rootSyms) { PSObject val = _GetValue(rootSym); int i = 1; var sbPrefix = new StringBuilder(tokens[0]); while (i < tokens.Length) { if (val == null) { // TODO: what? // TODO: Some sort of "symbol null" exception? WriteError(new ArgumentException(Util.Sprintf("Symbol \"{0}\" was null; cannot dereference {1}.", sbPrefix.ToString(), tokens[i])), "SymbolNull", ErrorCategory.ObjectNotFound, sbPrefix.ToString() + "." + tokens[i]); break; } if (0 == tokens[i].Length) { // A trailing '.'? Or consecutive '.'s? WriteError(new ArgumentException("You need something after the '.' (or between \"..\")."), "MissingSymbolToken", ErrorCategory.InvalidArgument, Name); val = null; break; } // TODO: Wildcard support? var prop = val.Properties[tokens[i]]; if (null == prop) { // TODO: Some sort of "symbol field not found" exception? WriteError(new ArgumentException(Util.Sprintf("Symbol \"{0}\" has no such property {1}.", sbPrefix.ToString(), tokens[i])), "SymbolLacksRequestedProperty", ErrorCategory.ObjectNotFound, sbPrefix.ToString() + "." + tokens[i]); val = null; break; } val = (PSObject)prop.Value; sbPrefix.Append('.').Append(tokens[i]); i++; } // end while( more tokens ) if (null != val) { WriteObject(val); } } // end foreach( rootSyms ) } // end else( not '*' ) } // end _DumpByName()