romperse la cabeza

Etymology
lit. 'to break one's head'.

Verb

 * 1)  to rack one's brain