So when this happens it feels like you're really in the shitter and I guess you kind of are. You're going to have to waste a couple days depending on which country you're in sorting it out but in the grand scheme of things you'll be able to get another and continue on your road to everywhere. Below I've written you a 'emergency to do' list if this happens to you.
Don't panic. You're going to panic I know but try to keep yourself in a realistic zone of panic and not freak out too much. When you're freaking out you become a target for other crime as you're not going to be focuses as much on keeping your other valuables safe.
Find out your nearest embassy. These are the guys who will be able to replace your passport and give you all the advice you need. Use an Internet cafe, a friends phone or other digital device as this is easily google-able. You can also take the opportunity to find information on what to do in the country you're in by looking at
Get to the embassy, unless specific advice tells you otherwise. I would generally steer you towards to home office travel advice as your first port of call - https://www.gov.uk/foreign-travel-advice
Now, if your whole bag has been stolen it probably means that a big chunk of your money, if not all it is gone along with your debit/ credit cards, phone and any other means of accessing money. But, backpackers are so of the most generous people I've ever met. I've seen them give up their clothes, chargers and money to help other travellers in the past with no guarantee they'll ever get paid back. I think it's in the hope that if they had everything stolen, someone would help them just as much in return. There will be someone who will listen to your pleas for help and may even give up their day and accompany you to the embassy to give you support - I've seen it happen.
You will get your passport. Once you are at that embassy you’ll get sorted and you can relax. You’ll be missing your cool travel stamps from all the places you’ve been, and you’ll have to reapply for visas if you’ve still got more wanderlust in you but the embassy will be able to help you with that or at least tell you where to go. I would also report your passport missing again once you get home, just to make sure it matches the database there so that you’re not going to be at risk of identity fraud (and it would be seriously unlikely anyway). It’s also temporary, so you’ll have to get a new one when home anyway and we all know how fun it is getting that passport picture redone…
The key is not to panic, the country you’re in is no more dangerous or scary without your passport. Nothing scary is going to happen, no-ones going to descend and send you to jail. It’s always horrible to have lost your stuff or have it stolen but you’re always going to be looked after. And thumbs up for the friends of mine who are travelling to Iran now as they’ve reopened their embassy - yay!