In this paper we establish a formula, expressing the generalized Atiyah-Patodi-Singer index in terms of eta invariants of domain-wall massive Dirac operators, without assuming that the Dirac operator on the boundary is invertible. Compared with the original Atiyah-Patodi-Singer index theorem, this formula has the advantage that no global spectral projection boundary conditions appear. Our main tool is an asymptotic gluing formula for eta invariants proved by using a splitting principle developed by Douglas and Wojciechowski in adiabatic limit. The eta invariant splits into a contribution from the interior, one from the boundary, and an error term vanishing in the adiabatic limit process.