Compounds of Formula I: and pharmaceutically acceptable salts thereof, wherein ring A, ring B, W, m, D, R2, R2a, R3, R3a, and Z are as defined herein, are inhibitors of Trk kinases and are useful in the treatment of pain, cancer, inflammation, neurodegenerative diseases and certain infectious diseases.一種通式I所示的化合物及其醫藥上可接受的鹽,其中環A,環B,W,m,D,R2,R2a,R3,R3a和Z如本文所定義,其為Trk激酶的抑制劑,並且可以用於治療疼痛、癌症、炎症、神經退化性疾病和某些傳染病。