To rack one's brains without arriving at a solution; to mull over something endlessly and be unable to decide (literary/old-fashioned nuance).
彼は将来の進路について思いあぐねていた。
He was racking his brains over his future path.
問題の解決策を思いあぐねて、何日も眠れなかった。
I was unable to find a solution and racked my brains for days without sleeping.