The thing I see in this hypothetical is that just about everyone forgets one MAJOR factor....
You (ahem) are not LEO and have no power to do anything except shoot IF you believe that your life or the life of another is in immediate danger.
Yelling at the guy with a gun pointed at your child, spouse, mother, etc is STUPID beyond belief. Shoot him in the back from behind cover and sort it out later. There's tons of stories where undercover cops have been shot by uniformed cops so how could it be so unthinkable that a CHL shoots an undercover cop who has his weapon pointed at the CHL's family member. A good lawyer will work wonders for your defense to the DA before it even gets to trial. And if it goes to trial, your defense is going to be based upon what the law REQUIRED you to do (defend life) and the fact that the LEO was undercover/off duty/rogue, failed to ID himself, and caused you to believe that either your life or the life of your immediate family member were in danger. A dead cop cannot refute your belief so you get the benefit of the doubt. Shoot him to slide lock and hit your target every time. But you better damn well be positive in your belief that the guy with the gun IS a BG and your family member had better be totally innocent of anything including parking tickets.
If the LEO (if he is truly LEO) has a gun pointed at your best friend in the approved LEO fashion, then I'd suggest you back off, dial 911 then announce yourself from cover and wait and see what's going down. There's a world of difference between family and best friend and you have no maternal/paternal instinct defense so shooting an actual undercover LEO who was arresting your best friend WILL get you a ticket to jail.
Remember, you only have the right to draw and shoot in self defense or the defense of another who is in imminent danger of death. Not arrest or detain the BG or yell before shooting, or any of the other silly notions that have been discussed here. If you believe then shoot the guy - it's why you carry.
And lastly, if the scenario is quiet without a lot of yelling, sirens, etc then it's likely the guy with the gun isn't LEO. Arrests in public parking lots tend to be noisy with a lot of commotion going on. Turning the corner at Walmart to find someone with a drawn weapon and no one even noticing is a giveaway that it's not an arrest.
And for you LEO's who are going to flame me for my opinion, if you are standing there with a gun pointed towards my family member while wearing flipflops, burmuda shorts and a Gilligan's Island T-shirt I ain't a gonna believe you're on duty LEO. And if you're not on duty, what the heck are you doing trying to forcibly arrest someone in that getup without backup. Off duty LEO shouldn't be permitted to arrest or detain unless life is in imminent danger. Other property crimes get the best witness possible.
And don't undercover cops get support so that "they" never have to be the one to make the actual arrest? Isn't that the job of their backup team?
My take, if the gun is pointed at immediate family just shoot him. If it's pointed at grown siblings/friends, call 911. And if your friend asks why you didn't shoot, explain the difference between protecting yourself/family and best friends. Best friends get to protect themselves cuz it ain't your job to do it for them.