Preheat the oven to 375 degrees. In a large skillet, melt the butter over medium-low heat. Add the onions and sugar. Cook, stirring occasionally, until the onions are deep brown and very soft, about 45 minutes. Season with salt and pepper; let cool.
Meanwhile, place the bread on a foil-lined baking sheet. Using a serrated knife, cut a 3/4-inch crosshatch pattern into the bread, cutting almost to the bottom of the loaf. (Be careful to not cut completely through the loaf.)
Set aside 1 tbsp. of the onion mixture; stuff the remaining mixture into the cuts in the bread, pushing as far down as possible without breaking the loaf apart. Repeat with the cheese. Top the loaf with the remaining onion mixture; sprinkle with cracked pepper.
Bake, tenting with foil if browning too quickly, until the top is browned and the cheese is bubbly, about 20 minutes. Transfer to a platter; season with more pepper. Serve with a knife for cutting into wedges (or guests can tear off pieces with their hands!).