Wintellect Blogs

Single Stepping a PowerShell Pipeline

John Robbins

11 Dec , 2014  

shutterstock_135487823

As I was building up a moderately complicated pipeline in PowerShell, I was having some trouble and really wished there was a way to single step the pipeline so I could see the state of each item as it was processed. I wasn’t sure this was possible, but it is and I thought others might find it helpful. The magic is in the super powerful Set-PSBreakpoint cmdlet.

Because Set-PSBreakpoint can create breakpoints on not only lines and variable reads/writes, but also commands, I thought I’d try setting a breakpoint in the PowerShell console on one of the commands in the pipeline and it worked great! In the example below I will set a breakpoint on the Get-ChildItem cmdlet and when the breakpoint is hit, use the command line debugger to step through parts of the pipeline (the ‘s’ command is step into)

  1. PS C:\Junk> Set-PSBreakpoint -Command Get-ChildItem
  2.   ID Script   Line Command        Variable    Action
  3.   – ——   —- ——-        ——–    ——
  4.    0               Get-ChildItem
  5. PS C:\Junk> Get-ChildItem *.exe | ForEach-Object { $_.Name }
  6. Entering debug mode. Use h or ? for help.
  7. Hit Command breakpoint on ‘Get-ChildItem’
  8. At line:1 char:1
  9. + Get-ChildItem *.exe | ForEach-Object { $_.Name }
  10. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. [DBG]: PS C:\Junk>> s
  12. At line:1 char:38
  13. + Get-ChildItem *.exe | ForEach-Object { $_.Name }
  14. +                                      ~
  15. [DBG]: PS C:\Junk>> s
  16. At line:1 char:40
  17. + Get-ChildItem *.exe | ForEach-Object { $_.Name }
  18. +                                        ~~~~~~~
  19. [DBG]: PS C:\Junk>> s
  20. Foo.exe
  21. At line:1 char:48
  22. + Get-ChildItem *.exe | ForEach-Object { $_.Name }
  23. +                                                ~
  24. [DBG]: PS C:\Junk>>
Read more

,

Wintellect Blogs

Wintellect.Analyzers: Five New Roslyn Diagnostic Analyzers and Code Fixes

John Robbins

17 Nov , 2014  

shutterstock_149177681

When I first saw the Roslyn compiler, I was thrilled! For once the compiler was not going to be a black hole where source code comes in and on the other side of the worm hole a binary comes out. With open extensibility there’s going to be some amazing tools developed that were impossible to do any other way. With this week’s release of the Visual Studio 2015 Preview, the Roslyn API is solid and ready for extension!

We have posted on Wintellect’s GitHub account our first five analyzers and code fixers we wrote to explore that part of the API. They should give you a good idea how to get started writing your own new rules. Here’s the initial set of rules:… Read more

, ,

InfoGraphic

The Debugging Process

John Robbins

30 Oct , 2014  

Read more

,

Wintellect Blogs

Interviewed on the Hello World Podcast

John Robbins

3 Jun , 2014  

Shawn Wildermuth has been doing the Hello World Podcast for a while and it’s very interesting to hear about how great developers got started and what they’ve learned along the way. For the June 2nd edition, Shawn interviewed me! You can listen to it here: http://wildermuth.com/hwpod/27_John_Robbins. If you ever wanted to know what being a Green Beret does to help you in the software world, here’s your chance to find out. We even talked about some old NuMega stories, too. You’ll also find out why both Shawn and I both dream of growing up and being as half as good as fellow Wintellectual Jeremy Likness someday. Speaking of Jeremy, make sure to listen to his interview as well: http://wildermuth.com/hwpod/1_Jeremy_LiknessRead more

Wintellect Blogs

Windows Server 2012 Essentials Client Restore vs. Microsoft Surface Pro

John Robbins

9 Apr , 2014  

In this corner we have a Microsoft Surface Pro that needs to have a full client restore. In that corner we have Microsoft’s own Windows Server 2012 Essentials that contains said full client backup. Let’s get ready to rumble! ™ (I hope I don’t owe Michael Buffer money for using his trademark. He’s made over $400 million from it!) For what would seem like a simple task of restoring a full back up to a new Surface Pro nearly put me down for the count. Given the body blows I went through I wanted to save someone else the pain and show you how I got it to work. I happened to be restoring a Surface Pro here but these steps will apply to anyone trying to restore any modern computer that does not have an Ethernet port.

When I read through the Server 2012 Essentials documentation for performing a full client restore, a big note in the middle of the page gave me reason to bob:

“Windows PE does not support wireless connections. Because of this, the computer being restored must be physically connected to the small business network.”

That’s a solid upper cut to the jaw because a Surface Pro is a wireless only machine.… Read more

Wintellect Blogs

Initial ASUS Vivo Tab Note 8 Review

John Robbins

7 Apr , 2014  

Eight days ago I went through the five Kübler-Ross stages of grief in about 490 milliseconds as I watched my Surface Pro fall out of my backpack and kiss the concrete directly on the upper right hand corner. I didn’t even have to open the Type Cover to know that the glass would have made a spider proud. The Microsoft hardware designers should be happy to know that the machine still boots and is functional, but touch is not so hot when a swipe leads to a bloody finger. While I’d been eying the ASUS Vivo Tab Note 8 because of its form factor and pen support, I couldn’t really justify it because I already had an excellent tablet. By dropping my Surface Pro, I was able to justify taking the plunge on the ASUS.

While most people using the Surface Pro are using it 60% or more of the time as a desktop replacement, my usage had become more and more pure tablet. I’d still occasionally do development on my Surface Pro, but it’s hard to beat my Macbook Pro as the best machine for running Visual Studio. As a tablet OS, I very much like Windows 8.1 so was reading with the Kindle app, the Economist magazine app, web browsing, and doing a lot of email with the very good Windows 8.1 mail app.… Read more

Wintellect Blogs

A Behavior Change in Visual Studio 2013 .NET Breakpoints

John Robbins

17 Mar , 2014  

One of my favorite tricks is to use Visual Studio breakpoints to call a method to force state changes when testing code. There’s just some times where calling a method at a breakpoint is the fastest way to create a test. To call a method at a breakpoint, set a regular location breakpoint, right click on the breakpoint circle in the gutter, and select Condition. That will get you the wonderful Breakpoint Condition shown below.

clip_image002

The Visual Studio team didn’t put full Intellisense in because they were feeling wild and crazy one day. They want you to call methods from breakpoints. If this technique is new to you, I can already hear your mind racing away with ideas on how it can help you.

There has been a change in the implementation of how methods are called from conditional breakpoints in Visual Studio 2013. Let’s take a look at how things worked in Visual Studio 2012 first. Here’s a method I want to call from the a conditional breakpoint, which you can see sets state.

  1. private Boolean CallFromBreakpoint()
  2. {
  3.     this.Data = "CallFromBreakpoint";
  4.     this.MoreData = "CallFromBreakpoint";
  5.     return true;
  6. }

 

I’ve set a conditional breakpoint in Visual Studio 2012 and using an instance of the class am calling the CallFromBreakpoint method.… Read more

Wintellect Blogs

Displaying Multiple .NET Objects with WinDBG’s Command Language

John Robbins

12 Mar , 2014  

While we are getting some nice tools from Microsoft for analyzing our memory, there’s still a lot of gaps where you have to resort to WinDBG and SOS. A perfect example that I’ve run into is looking at variables/types that are in different app domains because the Visual Studio debugging environment has essentially zero support for app domains. That’s normally not a problem for most people, but there’s a lot of things that you just need WinDBG and SOS to figure out. In this article I wanted to show a little trick I use with the WinDBG command language.

If you’re not familiar with WinDBG or SOS, you can watch my Introduction to WinDBG and SOS Commands and Minidump videos on WintellectNOW. Use the code JOHNR-2013 to get two free weeks of viewing pleasure.

The WinDBG command language allows you to write looping and logic statements using commands like .if, .while, .foreach, .printf, etc. You can use the command language with conditional breakpoints or write complicated analysis scripts in it. Like anything else in WinDBG, it’s barely documented and has no debugger, but a little trial and error take you a long way.

A very common situation when looking at a minidump is that you want to look at all of the objects of a particular type.… Read more

Wintellect Blogs

How Many Secrets do .NET PDB Files Really Contain?

John Robbins

8 Mar , 2014  

Now that Devscovery is over, it’s time to get back to answering questions about one of my favorite subjects: PDB files! Yes, I lead an extremely exciting life if PDB files set my heart racing. Maybe they have a pill for that.

In my blog post on PDBs and remote debugging Patrick asked an interesting question about .NET PDB files:

Hi John,

I find it rather strange that the PDB files for .Net applications should be on the remote machine, not the local machine.

After our release builds, we store all PDB and EXE files on a symbol server. That way we can easily debug crash dump (.DMP) files sent to us by customers.

Sometimes we use remote debugging to solve a problem at a customer (using VPN over the Internet), and for native applications, the debugger nicely gets the .PDB file from the symbol server.

However, if we would introduce .Net in our applications, would this mean that we have to send the .PDB file to our customer?

This will not only be a rather slow task (our PDB files can easily be 200 MB), but also this means that we have to give all of our debug information in the hands of our customer.Read more

Wintellect Blogs

Correctly Creating Native C++ Release Build PDBs

John Robbins

8 Mar , 2014  

In my ongoing discussion of PDB files and debugging, Sa Li had a great question:

Should the final release native program also generate the pdb files before being published?

If switching on the pdb in link setting, what kind of info would be added into the .exe executable file?

I found our program grows a lot after turning on this flag. Does that have anything which can reveal some sensitive secrete of our program?

If you’ve read any of my books that discussed native debugging, I’ve been shouting that you must build PDB files for all builds. Of course, if you are paid by the hour don’t build PDB files so debugging is massively harder and you have guaranteed employment. There’s nothing like debugging yourself a new car. Just kidding!

One of the issues that you bump into with debugging release build native C++ applications are the compiler optimizations. For example, many local variables disappear because instead of putting them on the stack, as what happens in debug builds, the code generator puts them in registers instead. Additionally, release builds aggressively inline calls to functions so the code generator puts the body of the function directly in the calling method.… Read more