A dislocation dynamical theory of the ductile-to-brittle transition