Chop the onions and fry in butter, once softened, add the mushrooms, until golden brown. Sprinkle in the flour, gradually add warmed stock and mix well. Cover, and simmer for 15 minutes. Add the Madeira in the last 5 minutes of cooking. Season with salt and pepper to taste. Serve with roast meat or steak.