Its definitely a complicated subject. The question of when we are supposed to choose life or death depends on the situation. In a case, where someone tells me, eat pig or die, or if for some reason, eating pig will cure me of some lethal sickness, then I fulfill a positive commandment of "and live by them (Lev. 18:5)". In that case you're absolutely right.
On the other hand, there are 3 commandments and 2 cases where I'm required to die instead. The three commandments are if I'm forced to commit adultery, murder, or idol worship. These three apply no matter what. The the two cases for other commandments are (1) if the person is forcing the Jew to transgress a prohibition for the sake of getting him to transgress and there are 10 Jews present, or (2) if the government is making a decree against practicing Judaism.
So to answer your questions, in the case of a child being hit by a truck, its permitted and even required to profane the Sabbath in order to protect the child's life. Similarly, in the case of David, his men were on the verge of death, so they were also permitted to eat the bread. In the case of the Nazis, its hard to give a blanket answer. On the one hand, they weren't out to specifically wipe out Judaism as much as wipe out the Jewish people. That's an important distinction. The fact that they made people work on the Sabbath, isn't part of their plan to wipe out Judaism per se, but a side-effect of not allowing breaks from work. On the other hand, many prisoners did risk their lives to perform the commandments to the best of their ability, such as sneaking in prayer books and phylacteries, fasting on the Day of Atonement, lighting Hanukkah candles, etc. Keep in mind that in those circumstances, even if they wanted to, they're resources were limited. So its a really complicated question that can only be answered on a case by case basis and there's actually a set of responsa (5 books) by a
rabbi who went though Auschwitz dealing with questions that were presented to him in the camp, often about when they can give up their lives or not. So that's a complicated discussion.