I need help with taking the derivative of some quantities with respect to a diagonal matrix. Let say the diagonal matrix is $\boldsymbol{X}_d = \text{diag} \{ x_1, \dots, x_d \}$ (pardon my notation). I need to obtain the following derivatives $$\frac{\partial}{\partial \boldsymbol{X}_d} \text{Tr} \{ \boldsymbol{A} \boldsymbol{X}_d \boldsymbol{B} \} \quad \text{and} \quad \frac{\partial}{\partial \boldsymbol{X}_d} \ln | \boldsymbol{A} \boldsymbol{X}_d |.$$
Initially, I naively tried the formulas for the general matrix, but after I obtain the estimation of $\boldsymbol{X}_d$, I did not get a diagonal matrix, which does not make sense, so I know there must be something special with taking the derivative with respect to a diagonal matrix. I did not find many resources on this topic, so I want to post the question and get help. Please help me if you can. Thank you so much.