Write $\alpha = a/b$ and substitute $\tan x = \alpha t$ to obtain
$$ \int_{0}^{\frac{\pi}{2}} \frac{x}{a^2\cos^2 x + b^2\sin^2 x} \, dx
= \frac{1}{ab} \int_{0}^{\infty} \frac{\arctan(\alpha t)}{1 + t^2} \, dt
=: \frac{1}{ab}I(\alpha). $$
Then
\begin{align*}
I'(\alpha)
&= \int_{0}^{\infty} \frac{t}{(1+t^2)(1+\alpha^2 t^2)} \, dt \\
&\hspace{1.5em} = \left[ -\frac{1}{2(1-\alpha^2)} \log\left( \frac{1+\alpha^2 t^2}{1+t^2} \right) \right]_{0}^{\infty}
= -\frac{\log \alpha}{1 - \alpha^2}.
\end{align*}
Now it is easy to check that, if we write $\chi_2(z) = \int_{0}^{z} \frac{\operatorname{artanh} \xi}{\xi} \, d\xi$ for the Legendre chi function, then
$$ \frac{d}{d\alpha} \chi_2\left(\frac{1-\alpha}{1+\alpha}\right) = \frac{\log \alpha}{1-\alpha^2}. $$
So it follows that
$$ I(\alpha) = \chi_2(1) - \chi_2\left(\frac{1-\alpha}{1+\alpha}\right) = \frac{\pi^2}{8} + \chi_2\left(\frac{\alpha-1}{\alpha+1}\right). $$
Plugging this back and manipulating a bit, we obtain
$$ \int_{0}^{\frac{\pi}{2}} \frac{x}{a^2\cos^2 x + b^2\sin^2 x} \, dx
= \frac{1}{ab} \left( \frac{\pi^2}{8} + \chi_2\left(\frac{a-b}{a+b}\right) \right). $$